MySQL Comments
In this page:
Single-Line Comments with Double Dash
A double-dash (--) starts a comment that runs to the end of the line, but standard SQL requires a space immediately after the dashes or MySQL may not recognize it as a comment at all.
Example: Single-Line Comments with Double Dash
-- This is a comment
SELECT 1;
Single-Line Comments with Hash
The hash symbol (#) is a MySQL-specific single-line comment marker that behaves like the double-dash but, unlike it, doesn't require a trailing space — a small but easy-to-forget difference between the two styles.
Example: Single-Line Comments with Hash
#This is a MySQL-specific comment
SELECT 1;
Multi-Line Comments
Block comments start with /* and end with */, and can span multiple lines, which makes them the right choice for longer explanations of why a complex query is structured the way it is.
Example: Multi-Line Comments
/* This is a
multi-line comment */
SELECT 1;
Comments inside SQL Statements
You can drop a block comment mid-statement, right next to a column name or clause, to document exactly what that piece does without breaking the SQL syntax around it.
Example: Comments inside SQL Statements
SELECT name /* the customer's full name */ FROM customers;
Executable Comments
MySQL supports a special executable comment syntax (/*! ... */) that other database systems simply ignore as a normal comment, letting you write MySQL-specific optimizations that stay portable to other engines.
Example: Executable Comments
SELECT /*! SQL_NO_CACHE */ * FROM customers;
Chapter Quiz — Complete all 8 topics to unlock
0/8 topics done
Complete these topics first: