SQL Server Central is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
Search:  
 
 

The case against using single-line comments

By Cade Bryant, 2003/01/21

Total article views: 162 | Views in the last 30 days: 9

This isn't a "script" per se - but rather an observation about a common issue in writing scripts.

I want to alert SQL programmers to the issues surrounding the use of single-line comments.  I try to avoid these whenever possible, and use block comments instead (except, of course, when commenting out the keyword GO).

The reason is that, if a script is copied into a text editor that "wraps" lines, some single-line comments could be broken up into multiple lines.  If one were to copy that code from the editor into Query Analyzer and execute it, the result will be a syntax error, or in the worst case scenario, the execution of dangerous and unwanted code.

I've actually seen this happen with scripts submitted to SQLServerCentral.com.  The text box wherein scripts are pasted on this site "wraps" the text, and I've seen several where single-line comments were broken up into multiple lines.

Below, I have written a couple of examples to illustrate the importance of this:
 

By Cade Bryant, 2003/01/21

Total article views: 162 | Views in the last 30 days: 9
Your response
 
 
 
Already registered?  

Free registration required

To read the rest of this article, and access thousands of other articles, we ask you to register on the site and subscribe to our newsletters.

Register

E-mail address:
Password:
Password (confirm):

  

Subscriptions

We ask you to register on the site and subscribe to our newsletters. Subscribing to our newsletters gets you:

  • ALL of our content (thousands of articles, scripts, and forum postings)
  • A daily newsletter (example)
  • A weekly news round up (example)
  • The opportunity to ask and answer questions in our forums
  • A daily Question of the Day to test and help you increase your knowledge of SQL Server.

We ask that you give the newsletter a try for a week. Over 200,000 SQL Server Professionals a day find it entertaining and useful. If not, you are welcome to unsubscribe at anytime.

Steve Jones
Editor, SQLServerCentral.com