Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Microsoft SQL Server: Programming FAQ

T-SQL Hints and Tips

T-SQL Best Practices - PART II - Naming Conventions by donutman
Posted: 5 Jul 04 (Edited 11 Feb 05)

Stored Procedures and Views
  • Do not preface a stored procedure with sp_. Commonly accepted prefixes are:
    1. sp or s (vw or v for views)
    2. s21 where the 21 refers to the program number that uses this SP. This has the advantage of keeping all SP's for program 21 together.
  • The balance of the name should include a description of its action, e.g.
    1. UpdateInvoice (note the use of Proper Case and no underscores)
    2. InsertEmployee
    3. SelectCustomer
    4. FindInvoiceItem
User Defined Functions
  • A prefix isn't needed for two reasons:
    1. When a function is called it must be prefaced by the ownerÆs name, e.g. dbo.FunctionName.
    2. You shouldn't be writing very many UDFs as they are inefficient.
Table Names
  • Table names require no prefix to identify them as their use makes it fairly obvious as long as Views have a prefix.
  • Use descriptive names, no abreviations and no plurals.  Some writers prefer to use plural where it seems appropriate, but my quarrel with them is that it is very difficult for everyone to agree when it is appropriate.  Consequently, it is easier to leave no doubt and make them singular.
  • Designate look-up tables with either a prefix or suffix that will always indicate the tables purpose, e.g. luTableName or TableNameLkU.
  • Designate many-to-many tables (conjoint table) by using an underscore between the associated table names, e.g. Product_Supplier.
  • Never use a name that requires the use of [ ].
Column Names
  • Avoid underscores, they look unnatural and slow the reader down.
  • Never use a column name that requires [ ].  Shame on Microsoft for excessive use of ID which requires the use of a table qualifier.
  • Use Proper Case, descriptive names and don't abbreviate.
  • Name primary keys with a suffix that denotes it data type.
    1. TableNameID for integer (the preferred choice for all primary keys).
    2. TableNameCode for varchar.
    3. TableNameKey (other data types).
  • Do not change the spelling of the primary key from a parent table when it's used in a child table.
  • Don't use acronyms unless they are well know by programmers or all employees of your company.
Alias Names
  • For tables use the initials from each word, e.g. TableName TN (note the absence of AS).
  • For computed columns use the form Alias=Expression rather than Expression Alias as it cannot appear as another column rather than an alias.

Back to Microsoft SQL Server: Programming FAQ Index
Back to Microsoft SQL Server: Programming Forum

My Archive

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close