When you’re writing code, you have some options when it comes to leaving comments:
- Double dashes at the start of a line:
- Block quotes around a section of text:
/* Comment! */
- No comment whatsoever:
The problem with the double-dash method is that there’s no terminator for it. If you end up pasting the query from a DMV where it’s not all nicely formatted, it’s pretty likely going to end up all on a single line.
With a long enough query, it can be a real pain to scroll across looking for comments and separating them to a new line so you can run the query.
What really sucks is that tools that can automatically format T-SQL for you can’t handle this either. If I could just right click and solve the problem, I’d be talking about that instead.
So, please: If you’re going to put comments in your code, use the block quotes.
Thanks for reading!
If this is the kind of SQL Server stuff you love learning about, you’ll love my training. I’m offering a 75% discount to my blog readers if you click from here. I’m also available for consulting if you just don’t have time for that and need to solve performance problems quickly.