Skip navigation

Tip: Commenting Out the GO Keyword in a Multiple-Batch SQL Script

If you try to comment out the GO keyword inside a batch run, you might not get the results you expect. For example, imagine that the following batch is part of a larger script and you need to comment it out during a testing phase:

SELECT * FROM authors
GO

To comment out the batch, you might try to use standard block comment markers on separate lines above and below the code you want to comment out:

/*
SELECT * FROM authors
GO
*/

But this change produces the error messages that Figure A and Figure B show. SQL Server's parser doesn't realize that the GO keyword is commented out. Instead, the parser sees two batches. SQL Server thinks the first batch contains the lines

/*
SELECT * FROM authors

and the second batch contains one line that consists of the */ comment marker. Instead, you need to comment out the batch by commenting out the GO keyword line separately, as the following examples show:

/*
SELECT * FROM authors
--GO
*/

or

/*
SELECT * FROM authors
/*GO*/
*/

The redundant comment markers clarify the code without affecting processing.

Hide comments

Comments

  • Allowed HTML tags: <em> <strong> <blockquote> <br> <p>

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.
Publish