This blog has been moved to http://dattatreysindol.blogspot.com.

Please visit http://dattatreysindol.blogspot.com for all updates from now on.


Thanks for visiting my blog.



- Datta




| 0 comments ]

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.

These conventions are purely based on my comfort level and there is no hard & fast rule that these are followed / should be following widely in the industry. One can define their own standards / conventions based on their comfort level to ensure consistency.

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