The MySQL server supports the # to end of line
, --
to end of line
and /* in-line or multiple-line */
comment
styles:
mysql> SELECT 1+1; # This comment continues to the end of line mysql> SELECT 1+1; -- This comment continues to the end of line mysql> SELECT 1 /* this is an in-line comment */ + 1; mysql> SELECT 1+ /* this is a multiple-line comment */ 1;
Note that the --
(double-dash) comment style requires you to have at
least one space after the second dash!
Although the server understands the comment syntax just described,
there are some limitations on the way that the mysql
client
parses /* ... */
comments:
mysql
interactively, you can tell that it
has gotten confused like this because the prompt changes from mysql>
to '>
or ">
.
These limitations apply both when you run mysql
interactively
and when you put commands in a file and tell mysql
to read its
input from that file with mysql < some-file
.
MySQL supports the `--' SQL-99 comment style only if the second dash is followed by a space. See section 1.8.4.7 `--' as the Start of a Comment.
Posted by Ken Menzel on Thursday August 15 2002, @6:21am | [Delete] [Edit] |
YOu may also embed non-ANSI MYSQL commands
or commands specifiec to a particular version in the
comment syntax using the /*!xxxx */ syntax See
section:
1.7.3 MySQL Extensions to ANSI SQL92
Posted by R. Tango-Lowy on Monday September 30 2002, @1:40pm | [Delete] [Edit] |
In version 3.23, a semicolon in a multiline
comment will cause an error. Including the GPL
header in a comment, for instance, will generate
lots of errors. (Legalese uses lots of semicolons).
Posted by Brat Wizard on Tuesday May 27 2003, @4:05am | [Delete] [Edit] |
Some tiny gotchas-- nothing serious. Using two dashes ('--') inside a regular comment block (/* ... */) __MAY__ confuse the parser and in which case you will get strange errors. Also using single apostrophe's (') can wig it out too. Not sure why this happens.
/*
this is a good comment
*/
/* this is a bad comment-- it has two dashes
and __MIGHT__ wig out the parser
(for some reason it doesn't always happen, haven't
figure out the how/when part yet)
*/
Posted by Stan Bartsch on Wednesday June 4 2003, @9:52pm | [Delete] [Edit] |
My guess is the Parser "Wigs Out" when you include the double dash on the same line as the */, so that it looks like this:
/* Start a Comment
-- Here's a nested comment */
Now, the parser saw the /* and the --, but because of the --, it didn't see the */ and so it thinks the original /* comment is still active. It closed the -- comment on the carriage return.
The parser should either NOT recognize nested comments, or be adjusted to allow for closing one comment while "technically" inside another.