Search notes:

SQL: comments

The SQL standard defines two kinds of comments:
A simple comment starts with two hyphens (--) and extends to the next new line or end of statement, whichever is first.
A Bracketed comment starts with a /* and extends to the next */.
In a comment that is introduced by a --, the /* is not recognized as a comment introducer.
Similarly, within /* … */ the -- does not comment out a the */.
Apparrently, some SQL dialects allow to nest /* … */ comments (among which there is T-SQL).
The following snippet tries to demonstrate all combinations in a dialect that does not allow nesting comments.. T is SQL text, c is comment:
TTT TTTT TT -- ccc ccc

TTT /* cc ccc
cc cccc
-- */ ccc ccc
ccc */ TTT

/* ccc ccc
ccc 
ccc -- */ TTT

-- /* ccc ccc
TTT TTTT
TTT -- */ ccc
With these rules, its possible to comment out or in a block of code while testing SQL statements with just two hyphens as is is shown below:
-- /*
This text is not a comment.
By just removing the two hyphens
at the beginning, it turns
into a comment.
-- */

Misc

The statement parser considers comments to be equivalent to new lines.
I believe that the standard can be interpreted to mean that bracketed comments can be nested.

See also

In MySQL, comments can also be introduced with a #. Additionally, it seems that -- needs to be followed by a space to be recognized as a comment.
A minimalistic C-Sharp class to remove SQL comments with regular expressions.

Index