You are here: Re: Naming Conventions « MsSQL Server « IT news, forums, messages
Re: Naming Conventions

Posted by Dan Guzman on 05/03/07 11:25

> So what would the appropriate and most up-to-date and standard naming
> be for SQL Server? My Guess:
>
> Orders
> =====
> Ord_Order_ID_Pk
> Ord_Customer_ID_Fk
> Ord_Order_Date

I would instead suggest:

CREATE TABLE dbo.Orders
(
Order_ID int NOT NULL,
Customer_ID int NOT NULL,
Order_Date smalldatetime
)

or perhaps:

CREATE TABLE dbo.Orders
(
OrderID int NOT NULL,
CustomerID int NOT NULL,
OrderDate smalldatetime
)

The purpose of a column name is to provide a clear name for the contents.
The 'Ord_' prefix here is redundant since columns are within the context of
the Orders table and can be qualified in queries when needed to avoid
namespace conflicts. The '_Pk' and '_Fk' suffix shouldn't be specified
since it does not describe the data the column contains.

Other naming variables include case of object and column names and whether
or not name segments are separated with underscores. Init-cap seems to be
the most popular in SQL Server. When you use init-cap naming, the
underscores are optional since the names are fairly readable with or without
the separator. The underscore separator is highly desirable when all
lower/upper case names are used, which is often favored by organizations
with case-sensitive collation standards.

Hungarian naming is discouraged for table/view/column names because these
names are exposed as the interface to database uses. Implementation-neutral
naming facilitates changing the underlying implementation with minimal user
impact. However, object type prefixes are commonly used for other object
types. I'm sure this is at least partly to avoid name conflicts within a
schema. Hungarian naming is somewhat optional for indexes since those have
a table scope. Using Hungarian naming for objects exposed only to
developers and DBAs is ok, IMHO.

Regardless of the naming convention you choose, follow it religiously.
Also, specify case consistently so that the application works under both
case sensitive and insensitive collations.


--
Hope this helps.

Dan Guzman
SQL Server MVP

"BillCo" <coleman.bill@gmail.com> wrote in message
news:1178184767.412407.28570@y80g2000hsf.googlegroups.com...
>
> I'm coming from a MS Access background and so I'm very used to and
> comfortable with the hungarian (Leszynski et al) naming conventions.
> However, I'm getting started into my first SQL Server Database and
> really want to use the appropriate up to date standard naming
> convention (ISO compliant).
>
> I think I have the general idea from raking though countless
> conflicting sites and posts, but I'm a bit stuck on what to do
> regarding pk / fk naming
>
> For example, in my MS Access world I would have two tables:
>
> tblOrders
> =======
> strOrderID
> intCustomerID
> dtOrderDate
> ...
>
> tblCustomers
> ==========
> intCustomerID
> strCustomerName
> ...
>
>
> So what would the appropriate and most up-to-date and standard naming
> be for SQL Server? My Guess:
>
> Orders
> =====
> Ord_Order_ID_Pk
> Ord_Customer_ID_Fk
> Ord_Order_Date
> ...
>
> Customers
> ========
> Cus_Customer_ID_Pk
> Cus_Customer_Name
> ...
>
> How close (or far) am I from "Celko Proof" naming here?
> All help gratefully accepted!
>

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация