What is TSQL2sday? Back in late 2009, Adam Machanic (blog | twitter) had this brilliant idea for a monthly SQL Server blogger event (the origin of TSQL2sday) on a unified topic. This month’s event is hosted by Amit Banerjee (blog | twitter) and the selected topic is “T-SQL Best Practices”.
This will be short and to the point. My #1 “best practice” tip when writing any code is to include comments! Whether a SELECT statement from a single table or a complex multi-table join using CROSS APPLY, please write a comment stating the objective of the command. You’ll be surprised how soon you forget why you wrote the command in the first place and why you wrote it the way you did.
I’ll open up the proverbial can of worms, though by stating my preferences for when to use block comments /* */ versus dash comments –.
I prefer to use the block method for actual comments.
/* Uncomment the code below in order to list all databases */
I prefer to use the dash comments to comment out actual T-SQL code.
–Select name from sys.databases
What’s your preference for T-SQL comment indicators?