Stored Procedures and Views
[ul][li]Do not preface a stored procedure with sp_. Commonly accepted prefixes are:[/li][ol]
[li]sp or s (vw or v for views)[/li]
[li]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.[/li][/ol]
[li]The balance of the name should include a description of its action, e.g.[/li][ol]
[li]UpdateInvoice (note the use of Proper Case and no underscores)[/li]
[li]InsertEmployee[/li]
[li]SelectCustomer[/li]
[li]FindInvoiceItem[/li][/ol][/ul]
User Defined Functions
[ul][li]A prefix isn't needed for two reasons:[/li][ol]
[li]When a function is called it must be prefaced by the ownerÆs name, e.g. dbo.FunctionName.[/li]
[li]You shouldn't be writing very many UDFs as they are inefficient.[/li][/ol][/ul]
Table Names
[ul][li]Table names require no prefix to identify them as their use makes it fairly obvious as long as Views have a prefix.[/li]
[li]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.[/li]
[li]Designate look-up tables with either a prefix or suffix that will always indicate the tables purpose, e.g. luTableName or TableNameLkU.[/li]
[li]Designate many-to-many tables (conjoint table) by using an underscore between the associated table names, e.g. Product_Supplier.[/li]
[li]Never use a name that requires the use of [ ].[/li][/ul]
Column Names
[ul][li]Avoid underscores, they look unnatural and slow the reader down.[/li]
[li]Never use a column name that requires [ ]. Shame on Microsoft for excessive use of ID which requires the use of a table qualifier.[/li]
[li]Use Proper Case, descriptive names and don't abbreviate.[/li]
[li]Name primary keys with a suffix that denotes it data type.[/li][ol]
[li]TableNameID for integer (the preferred choice for all primary keys).[/li]
[li]TableNameCode for varchar.[/li]
[li]TableNameKey (other data types).[/li][/ol]
[li]Do not change the spelling of the primary key from a parent table when it's used in a child table.[/li]
[li]Don't use acronyms unless they are well know by programmers or all employees of your company.[/li][/ul]
Alias Names
[ul][li]For tables use the initials from each word, e.g. TableName TN (note the absence of AS).[/li]
[li]For computed columns use the form Alias=Expression rather than Expression Alias as it cannot appear as another column rather than an alias.[/li][/ul]
-Karl
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.