(mysql.info.gz) ANSI diff comments
Info Catalog
(mysql.info.gz) ANSI diff Views
(mysql.info.gz) Differences from ANSI
1.5.5.7 `--' as the Start of a Comment
......................................
Some other SQL databases use `--' to start comments. MySQL Server uses
`#' as the start comment character. You can also use the C comment
style `/* this is a comment */' with MySQL Server. Comments.
MySQL Server 3.23.3 and above support the `--' comment style, provided
the comment is followed by a space (or by a control character such as a
newline). The requirement for a space is to prevent problems with
automatically generated SQL queries that have used something like the
following code, where we automatically insert the value of the payment
for `!payment!':
UPDATE account SET credit=credit-!payment!
Think about what happens if the value of `payment' is a negative value
such as `-1':
UPDATE account SET credit=credit--1
`credit--1' is a legal expression in SQL, but if `--' is interpreted as
the start of a comment, part of the expression is discarded. The result
is a statement that has a completely different meaning than intended:
UPDATE account SET credit=credit
The statement produces no change in value at all! This illustrates that
allowing comments to start with `--' can have serious consequences.
Using our implementation of this method of commenting in MySQL Server
3.23.3 and up, `credit--1' is actually safe.
Another safe feature is that the `mysql' command-line client removes
all lines that start with `--'.
The following information is relevant only if you are running a MySQL
version earlier than 3.23.3:
If you have an SQL program in a text file that contains `--' comments,
you should use the `replace' utility as follows to convert the comments
to use `#' characters:
shell> replace " --" " #" < text-file-with-funny-comments.sql \
| mysql DB_NAME
instead of the usual:
shell> mysql DB_NAME < text-file-with-funny-comments.sql
You can also edit the command file "in place" to change the `--'
comments to `#' comments:
shell> replace " --" " #" -- text-file-with-funny-comments.sql
Change them back with this command:
shell> replace " #" " --" -- text-file-with-funny-comments.sql
Info Catalog
(mysql.info.gz) ANSI diff Views
(mysql.info.gz) Differences from ANSI
automatically generated byinfo2html