SQL reference (MySQL and MariaDB dialects)

Comments

The three comment forms, executable comments, and how they are treated.

A comment is text the server skips. Raft DB reads the three forms of MySQL.

Syntax#

SQL
# text to the end of the line
-- text to the end of the line
/* text, possibly over several lines */
/*! code that is run */
/*!40101 code that is run */

Remarks#

  • -- starts a comment only when it is followed by a space, a tab or the end of the line (SELECT 1--1 is 1 - -1, not a comment), as in MySQL.
  • /* ... */ comments do not nest. An unterminated one is a syntax error (unterminated comment).
  • /*! ... */ is an executable comment: its content is read as code. An optional version number after the ! is read and ignored, whatever the server version is, so /*!40101 SET NAMES utf8 */ runs. Only /*! is read as code; MariaDB's /*M! ... */ is an ordinary comment here.
  • A comment can sit anywhere white space can, including in front of the first word: /* ping */ SELECT 1 runs (this is what some drivers send as a health check).
  • Optimizer hints (/*+ ... */) are ordinary comments and are ignored.

Examples#

SQL
SELECT 1; # one
SELECT 2; -- two
SELECT /* three */ 3;
/*!40101 SET NAMES utf8 */;

See also#