Comment Syntax
This section details the different ways to add non-executable comments to your SQL statements and script files, including single-line & multi-line comments, and MariaDB-specific conditional comments.
There are three supported comment styles in MariaDB:
From a hash sign (
#) to the end of a line:
SELECT * FROM users;
# This is a comment
From a double dash (
--) to the end of a line. The space after the two dashes is required (as in MySQL).
SELECT * FROM users; -- This is a commentC style comments from an opening '
/*' to a closing '*/'. Comments of this form can span multiple lines:
SELECT * FROM users; /* This is a
multi-line
comment */Nested comments are possible in some situations, but they are not supported or recommended.
Executable Comments
As an aid to portability between different databases, MariaDB supports executable comments. These special comments allow you to embed SQL code which will not execute when run on other databases, but will execute when run on MariaDB.
MariaDB supports both MySQL's executable comment format, and a slightly modified version specific to MariaDB. This way, if you have SQL code that works on MySQL and MariaDB, but not other databases, you can wrap it in a MySQL executable comment, and if you have code that specifically takes advantage of features only available in MariaDB you can use the MariaDB specific format to hide the code from MySQL.
Executable Comment Syntax
MySQL and MariaDB executable comment syntax:
Code that should be executed only starting from a specific MySQL or MariaDB version:
The numbers, represented by '######' in the syntax examples above specify the specific the minimum versions of MySQL and MariaDB that should execute the comment. The first number is the major version, the second 2 numbers are the minor version and the last 2 is the patch level.
For example, if you want to embed some code that should only execute on MySQL or MariaDB starting from 5.1.0, you would do the following:
MariaDB-only executable comment syntax (starting from MariaDB 5.3.1):
MariaDB ignores MySQL-style executable comments that have a version number in the range 50700..99999. This is needed to skip features introduced in MySQL-5.7 that are not ported to MariaDB 10.x yet.
Note: comments which have a version number in the range 50700..99999 that use MariaDB-style executable comment syntax are still executed.
Statement delimiters cannot be used within executable comments.
Examples
In MySQL all the following will return 2: In MariaDB, the last 2 queries would return 3.
The following executable statement will not work due to the delimiter inside the executable portion:
Instead, the delimiter should be placed outside the executable portion:
This page is licensed: CC BY-SA / Gnu FDL
Last updated
Was this helpful?

