Click here to Skip to main content
Licence CPOL
First Posted 21 Sep 2006
Views 56,334
Downloads 1,065
Bookmarked 34 times

T-SQL Coding Standard

By | 1 Oct 2008 | Article
T-SQL Coding Standard - for programming the Microsoft SQL Server 2005 (DRAFT)
 
Part of The SQL Zone sponsored by
See Also

Introduction

I am currently working on a T-SQL coding standard to formalize our work. Having been inspired by the IDesign C# Coding Standard, I made this T-SQL Coding Standard Document. Maybe this will have some value for the community. It is work in progress and I intend to update it as my experience with its implementation continues.

Unfortunately, I wrote the document in Word using loads of formatting and CodeProject's editor cannot display the document directly. Instead, I leave the document here in a zip for download.

When the document has matured some more, I will reformat it in HTML and modify this article.

Casper Leon Nielsen - 21. Sep 2006. (modified 1st October 2008)

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

About the Author

Casper Leon Nielsen

Architect
HelloGroup
Denmark Denmark

Member

Casper Leon Nielsen is a MCP/MCAD and is currently employed by HelloGroup a/s - a technical savy (yes that whats they are calling it these days) company.

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board. (secure sign-in)
 
Search this forum  
 FAQ
    Noise  Layout  Per page   
  Refresh
GeneralNice Pinmemberramakrishnankt20:22 22 Nov '11  
QuestionAny Update? Pinmemberjhigaki6:06 9 Jul '08  
AnswerRe: Any Update? PinmemberCasper Leon Nielsen23:21 30 Sep '08  
GeneralTable Naming - Statement Formatting PinmemberAhmed_Barakat6:16 31 Jan '08  
GeneralRe: Table Naming - Statement Formatting PinmemberCasper Leon Nielsen23:19 30 Sep '08  
QuestionNOLOCK? PinmemberRhodesie6:33 28 Sep '06  
AnswerRe: NOLOCK? PinmemberCasper Leon Nielsen23:12 28 Sep '06  
GeneralRe: NOLOCK? PinmemberCasper Leon Nielsen0:29 29 Sep '06  
GeneralRe: NOLOCK? PinmemberRhodesie22:59 1 Oct '06  
Answerderived tables PinmemberCasper Leon Nielsen23:15 28 Sep '06  
GeneralDiscussion on joelonsoftware PinmemberCasper Leon Nielsen10:50 24 Sep '06  
Generalprefixing stored procedures with sp_ is bad practice PinmemberKinStephen13:13 21 Sep '06  
AnswerAnd the standard says you shouldnt PinmemberCasper Leon Nielsen20:53 21 Sep '06  
GeneralRe: And the standard says you shouldnt PinmemberKinStephen7:21 22 Sep '06  
AnswerConclusion [modified] PinmemberCasper Leon Nielsen8:33 22 Sep '06  
Hi Stephen
 
Thanks for the input!
 
Well...It all boils down to being a question of stylistic taste:
Do we abbreviate stored procedures as "sp", "usp" or "p". In this standard, as is the case with standards generally, I had to make some choices on what to name things and "sp" seemed, and still seems, a natural choice for stored procedures.
 
In your first message you incorrectly stated that it was a technical question and I argumented that it wasnt - then you progressed onto stating "the standard is incorrect", not by any technical argument, but rather a feeling that using the abbreviation "sp" to indicate a stored procedure would clog the other use of that abbreviation, "sp_", which is used for system stored procedures - this is not my view.
 
Regarding your observations on procedures and functions: It is a very common misunderstanding, even amongst some of the more experienced people out there, that functions are technically equivalent to stored procedures - this is not the case however:
Syntactically the programmer uses these constructs very differently:
Stored procedures must be EXECUTE'd while UDF's can be used in ex. joins directly. This gives UDF's a massive usability advantage over stored procedures in set operations: We dont have to store the result set in an intermediate table to use the result, rather we can use it directly.
Furthermore the Sql Server engine is aware that that UDF's does not create side effects and have a constrained result type - and can therefore execute them quite differently and more effectively from stored procedures.
 
So in the end it boils down to a choice of taste: is "usp" or "sp" better to cover the term "Stored Procedure" - I say no as I like the stylistic beauty of only having two-letter prefixes. Furthermore the standard states that the underscore character is not to be used in naming UDO's, making it very easy for the programmer to visually differentiate between "sp_" and "sp".
 
Hope this makes sense,
 

Postscript...
Too many people feels uncomfortable with prefixing stored procedures with "sp" so I decided to change it to "usp" for the sake of democracy.

 
Casper Leon Nielsen
MCP/MCAD

GeneralRe: Conclusion PinmemberKinStephen11:28 22 Sep '06  
GeneralWhy not... PinmemberColin Angus Mackay3:41 21 Sep '06  
AnswerRe: Why not... PinmemberCasper Leon Nielsen3:57 21 Sep '06  
GeneralAvoid using the blob type - NOT Pinmember__alias3:24 21 Sep '06  
QuestionRe: Avoid using the blob type - NOT PinmemberCasper Leon Nielsen3:34 21 Sep '06  
AnswerRe: Avoid using the blob type - NOT Pinmember__alias10:14 21 Sep '06  
GeneralRe: Avoid using the blob type - NOT PinmemberCasper Leon Nielsen23:53 21 Sep '06  
GeneralRe: Avoid using the blob type - NOT PinmemberCasper Leon Nielsen0:38 22 Sep '06  
GeneralRe: Avoid using the blob type - NOT Pinmember__alias2:28 22 Sep '06  

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Mobile
Web02 | 2.5.120529.1 | Last Updated 1 Oct 2008
Article Copyright 2006 by Casper Leon Nielsen
Everything else Copyright © CodeProject, 1999-2012
Terms of Use
Layout: fixed | fluid