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.
March 26, 2002
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 authorsGO
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 authorsGO*/
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.
About the Author
You May Also Like