Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

T-SQL - Coding Standards & Best Practices

We see a lots of articles on the net and lots of documents are prepared by different project teams in the industry to present / capture the Conventions, coding standards etc. However in reality there is nothing like a Standard / convention as such in most cases. Conventions / Standards are defined to ensure consistency in the coding / documentation across various modules / projects.

Having said that, here are few of the conventions / standards that I use while writing T-SQL queries / functions / SPs etc.
  • Always type the SQL Keywords in CAPITAL Letters.
  • Use proper case while typing names of any database objects/entities. Usually database objects should be named using InitCap / Camel Case.
  • Use proper indentation.
  • Use Comments wherever necessary.
  • Name the Table aliases by concatenating the first letter of all the words in the name of the table. Example: If the table name is FactInternetSales then one of the possible alias is FIS. Define the aliases considering the conflicts if any with the other table aliases.
  • While executing stored procedures using "EXEC" command use the variable names while passing input values to the Stored Procedure (SP).
    Bad Example:

    USE AdventureWorksDW 
    GO
    EXEC sp_spaceused 'FactInternetSales' 
    GO


    Good Example:

    USE AdventureWorksDW 
    GO
    EXEC sp_spaceused @objname = 'FactInternetSales' 
    GO















Above snapshot shows few of the most commonly used T-SQL Statements.


This blog post is updated as and when I find something interesting which I feel like adopting as part of my coding.


This post first appeared on MyTechnoBook - Datta's Technical Notes..!!, please read the originial post: here

Share the post

T-SQL - Coding Standards & Best Practices

×

Subscribe to Mytechnobook - Datta's Technical Notes..!!

Get updates delivered right to your inbox!

Thank you for your subscription

×