Please Use Block Quotes For Code Comments In Your T-SQL

Options!


When you’re writing code, you have some options when it comes to leaving comments:

  • Double dashes at the start of a line: -- Comment!
  • 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.

clearly superior

Thanks for reading!

Going Further


If this is the kind of SQL Server stuff you love learning about, you’ll love my training. I’m offering a 75% discount on 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.



8 thoughts on “Please Use Block Quotes For Code Comments In Your T-SQL

  1. Holy cow!
    This is the best T-SQL hack after `SELECT TOP 0 * INTO new_table FROM old_table`

  2. I was once told that comments without a terminator (double-dashes) cause SQL Server to perform extra work when interacting with the code – however miniscule – vs. block quotes. Have you heard that before? Is there a way to prove that out?

Comments are closed.