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


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!

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

  1. 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?

Leave a Reply

Your email address will not be published. Required fields are marked *