Architecture

Naming Conventions

Since table names match object names, we use singular names and avoid names that require the use of brackets [ ]. Examples: "Invoice" rather than "Orders". "List" rather than "Groups".

Table Names
  • Table names require no prefix to identify them as their use makes it fairly obvious.
  • Views end with the word "View". Views that use sums end with the word "Summary".
  • Use descriptive names, no abreviations and no plurals. Some writers prefer to use plural where it seems appropriate, but it is very difficult for everyone to agree when it is appropriate. Otherwise you're relying on everyone to remember the plural forms for everything (Quick, what's the plural for stadium? Media?) (Answer: Stadia, and Media is already plural, the singluar is Medium). Consequently, it is better to leave no doubt and make them singular.
  • Designate many-to-many tables (conjoint table) by using a word that clearly implies a relation (e.g. Relation, InvoiceItem) or us an underscore between the associated table names (e.g. Site_Item). Since tables are also objects, the underscore is typically avoided.
  • 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 [ ].  Double shame on Microsoft for the use of ID which is very ambiguous and requires the use of a table qualifier or brackets.
  • Use Proper Case, descriptive names and don't abbreviate.
  • Name primary keys with a suffix that denotes its 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 a primary key from one table to the next.
  • 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.
Stored Procedures and Views
    Avoid using underscores in stored procedure names.
    Precede stored procedures names with:

    ins - Insert
    insUpd – Insert or Update
    sel - Select
    upd - Update

  • 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.
Related Links Transaction SQL Programming FAQ





© 2000-2024 DreamStudio & Partners Search Sign In