Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
Log in  ::  Register  ::  Not logged in

Nebraska SQL from @DBA_ANDY

I'm a forty-something Microsoft SQL Server DBA of 12+ years, a devoted husband, and a father of two young boys (with another coming soon!). I have been a DBA at a university, at a major bank, at a healthcare system, and I now work as a consultant with customers across the United States.

Double-Dash Comments, the Hidden Menace

While writing my last post on cleaning up old maintenance plans, I was reminded of something I heard in a presentation once (and unfortunately I can't remember who said it) that has stuck with me for the last several years:

Word Wrap is Your Enemy.

Why is this?  If you use double-dash inline comments:

--This is a comment, at least it is supposed to be.
SELECT COL01, COL02, from dbo.mytable

...and your code gets opened in Notepad/Wordpad or some other editor that utilizes Word Wrap, it could look like this:

--This is a comment, or at least it is sup
posed to be
SELECT COL01, COL02, from dbo.mytable

Good luck executing that code after it has been copy-pasted in this format into a query tool....something like "Improper syntax near 'posed'"

Even if you don't try to execute it, it can be difficult to read and troubleshoot when similar pieces of code are near each other and one line or the other is double-dash commented out.

So the hint to this is always, always, ALWAYS use star-slash comments /* */ even if your comment is short (even a single word) - it's not a bad habit to get into and doesn't cost you much (two extra characters) to protect you from this problem.

/*This is a comment, or at least it is sup
posed to be (and still is!)*/
SELECT COL01, COL02, from dbo.mytable 

Hope this helps!


Leave a comment on the original post [, opens in a new window]

Loading comments...