You can introduce comments in your SQL to specify text that should not be interpreted by MySQL. This is particularly useful in batch scripts for creating tables and loading data. MySQL specifically supports three kinds of commenting: C, shell-script, and ANSI SQL commenting.
treats anything between
*/ as comments. Using this form of commenting,
your comments can span multiple lines. For example:
/* * Creates a table for storing customer account information. */ DROP TABLE IF EXISTS ACCOUNT; CREATE TABLE ACCOUNT ( ACCOUNT_ID BIGINT NOT NULL PRIMARY KEY AUTO_INCREMENT, BALANCE DECIMAL(9,2) NOT NULL );
Within C comments, MySQL still treats single quotes and double quotes as a start to a string literal. In addition, a semicolon in the comment will cause MySQL to think you are done with the current statement.
Shell-script commenting treats
anything from a
# character to the end of
a line as a comment:
CREATE TABLE ACCOUNT ( ACCOUNT_ID BIGINT NOT NULL PRIMARY KEY AUTO_INCREMENT, BALANCE DECIMAL(9,2) NOT NULL ); # Not null ok?
MySQL does not really support ANSI SQL
commenting, but it comes close. ANSI SQL commenting is distinguished
-- to the end of a line. MySQL supports
two dashes and a space (
'-- ') followed by the
comment. The space is the non-ANSI part:
DROP TABLE IF EXISTS ACCOUNT; -- Drop the table if it already exists