SQL Comments in MariaDB: Line, Block, and Executable Comments
In MariaDB, # and -- followed by a space start comments that run to the end of the line. Use /* … */ for a block. Forms beginning with /*! or /*M! can execute SQL under their syntax and version rules.
Line comments and the space after two dashes
Connect to MariaDB and run these statements. They need no tables. Put a regular space immediately after the two dashes. If the SQL must run on another database, check whether it supports #.
# 4 + 3
SELECT 4 + 3 AS total; -- 7
-- 8 - 2, 8 - (-2)
SELECT 8 - 2 AS subtraction,
8--2 AS subtract_negative;
The first result is 7, and the next row contains 6 and 10. In 8--2, the dashes are followed by a digit, so MariaDB evaluates 8 - (-2). To add a note after a complete statement on the same line, put the semicolon before the comment.
Block comments and quoted strings
To write a comment across lines, open it with /* and close it with */. Place inline block comments between tokens. Splitting a keyword or identifier can break the statement.
/*
6 + 5
= 11
*/
SELECT 6 /* + 5 */ + 5 AS total;
SELECT '-- /* # */' AS literal_text;
The first result is 11. The second is the literal text -- /* # */ enclosed in single quotes. Keep block comments flat. If the client is still waiting for more input, check for a missing closing quote, */, or statement delimiter.
What changes when you comment out a WHERE clause
A common table expression (CTE) supplies three sample rows so you can compare the query results without modifying stored data. The two branches differ in whether WHERE active = 1 is applied.
WITH sample_rows AS (
SELECT 1 AS id, 1 AS active
UNION ALL SELECT 2, 0
UNION ALL SELECT 3, 1
)
SELECT 'filtered' AS result_set, id
FROM sample_rows
WHERE active = 1
UNION ALL
SELECT 'all_rows' AS result_set, id
FROM sample_rows
-- WHERE active = 1
ORDER BY result_set DESC, id;
The filtered branch returns IDs 1, 3. The all_rows branch returns 1, 2, 3. Remove the -- and both branches return only active rows. Before a real UPDATE or DELETE, run a SELECT with the same condition to confirm which rows are in scope. Check for a dangling AND or OR if the condition spans several lines.
Executable comments and server versions
In the MariaDB comment syntax reference, the /*! … */ form comes from MySQL, and /*M! … */ is MariaDB-specific. Version numbers 50600 and 100000 represent 5.6.0 and 10.0.0. Put the SQL statement’s semicolon outside the executable comment.
SELECT 5 /* +2 */ AS plain_comment;
SELECT 5 /*! +2 */ AS executable_comment;
SELECT 5 /*!50600 +2 */ AS after_50600;
SELECT 5 /*!50700 +2 */ AS skipped_50700;
SELECT 5 /*M!100000 +2 */ AS mariadb_100000;
MariaDB 11.4 returns 5, 7, 7, 5, 7. The /*!50700 … */ line returns 5 because MariaDB skips MySQL-style comments with version numbers from 50700 through 99999. That exception does not apply to the MariaDB-specific form. When reviewing a dump, read the SQL inside those comments and check its version condition.
The mariadb command-line client accepts --comments to preserve ordinary comments when sending statements to the server. Editors and drivers may handle them differently. Use comments to record the purpose of a query and keep credentials out of them, since the original script or server logs may retain their contents.




