In a program, a comment is a part of the source code that is ignored by the system. Comments are generally used for two purposes: (1) provide background information for future readers of that code, including our selves; (2) deactivate some code without deleting it yet—aka. commenting out. SQL supports comments too, of course.
While SQL comments are generally ignored by the engine, there are two side-effects worth mentioning. The first is that standard SQL does not really ignore comments, they are actually token separators like whitespace. The second side-effect is not standard SQL: Some systems look for special instructions inside comments—the so-called hints. Hints are, however, out of scope here but I wrote about them on Use The Index, Luke! before.
Standard SQL offers two flairs of comments: one starts by two dashes (--) and goes to the end of the line. The other starts with slash-asterisk (/*) and ends with asterisk-slash (*/). That might remind of comments in other programming languages. Unlike many other programming languages, the second form allows for nested comments in SQL. This is particularity useful when commenting out code that contains /*…*/ comments.
- Needs a white space after
--to avoid ambiguity with-(-<integer literal>) - Without nesting
- Except immediately after
select:select/**/* - The
#sign is the bitwise exclusive or (xor) operator
Of course, some vendors could not resist adding other forms of comments known from other programming languages. Obviously, they might be treated totally different by other systems.
Related
- Standard Features
- Implementation-defined elements
IV075, “The end-of-line indicator (newline)”
Normative References
The dash-dash (--) comment was already in SQL:1989 whereas the /*…*/ comment was introduced in ISO/IEC 9075-2:1999 as optional feature T351, “Bracketed comments”.

