SQL Comments, Please!


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.

BigQuery 2026-02-02bDb2 (LUW) 12.1.3cDuckDB 1.4.0H2 2.4.240MariaDB 12.1.2abMySQL 9.6.0abOracle DB 23.26.1bPostgreSQL 18dSQL Server 2025SQLite 3.51.0b-- comments/**/ comments# comments
  1. Needs a white space after -- to avoid ambiguity with -(-<integer literal>)
  2. Without nesting
  3. Except immediately after select: select/**/*
  4. 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.

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”.

You can’t catch up on 20 years of SQL evolution in one day. Subscribe the newsletter via E-Mail, Bluesky or RSS to gradually catch up and to keep modern-⁠sql.com on your radar.

About the Author

Photo of Markus Winand

Markus Winand provides insights into SQL and shows how different systems support it at modern-sql.com. Previously he made use-the-index-luke.com, which is still actively maintained. Markus can be hired as trainer, speaker and consultant via winand.at.

Buy the Book

Cover of “SQL Performance Explained”: Squirrel running on grass

The essence of SQL tuning in 200 pages

Buy now!
(paperback and/or PDF)

Paperback also available at Amazon.com.

Hire Markus

Markus offers SQL training and consulting for developers working at companies of all sizes.
Learn more »

Connect with Markus Winand

Subscribe mailinglistsSubscribe the RSS feedMarkus Winand on LinkedInMarkus Winand on XINGMarkus Winand on MastodonMarkus Winand on Bluesky
Copyright 2015-2026 Markus Winand. All righs reserved.
Legal | Contact | NO WARRANTY | Trademarks | Privacy and GDPR