MySQL allows annotations to be used in SQL code. This is useful for reading code. MySQL server supports 3 kinds of annotation styles:
1, "#" comment
All characters starting with the "#" character to the end of the line.
Mysql> Select @schema; #which Schema
+---------+
| @schema |
+---------+
| NULL |
+---------+
1 row in Set (0.00 sec)
Mysql> Select @schema; # which schema
+---------+
| @schema |
+---------+
| NULL |
+---------+
1 row in Set (0.00 sec)
There are no spaces between the characters "#" and the characters that follow.
2, "--" + "space" comment
with two dashes and a space comment, everything from the two dashes to the end of the line is treated as comments. all characters starting with the "--" character to the end of the line. Special Note: A double dash requires a 2nd dash followed by at least one space character (such as spaces, tabs, line breaks, and so on).
2.1. Cases without spaces:
Mysql> Select @schema; --which schema
+---------+
| @schema |
+---------+
| NULL |
+---------+
1 row in Set (0.00 sec)
;
Error 1064 (42000): You have a error in your SQL syntax; Check the manual-corresponds to your MySQL server version for the right syntax-use near '--which schema ' at line 1
Mysql>
2.2. Cases with spaces:
Mysql> Select @schema; --Which schema
+---------+
| @schema |
+---------+
| NULL |
+---------+
1 row in Set (0.00 sec)
3. "/* * *" single-line or multiline comment
Start with the "/*" character and End with "*/". The end sequence is not necessarily in the same row, so the syntax allows comments to span multiple lines.
3.1. Single-line Comment
3.1.1. No spaces between the content and the comment
Mysql> Select @schema; /*which schema*/
+---------+
| @schema |
+---------+
| NULL |
+---------+
1 row in Set (0.00 sec)
3.1.2. "/*" with a space between the comment contents
Mysql> Select @schema; /*which schema*/
+---------+
| @schema |
+---------+
| NULL |
+---------+
1 row in Set (0.01 sec)
;
Error 1064 (42000): You have a error in your SQL syntax; Check the manual-corresponds to your MySQL server version for the right syntax-use-near '/*which-schema*/' at Lin E 1
3.1.3. There is a space between the "* *" and the comment content
Mysql> Select @schema; /*which Schema */
+---------+
| @schema |
+---------+
| NULL |
+---------+
1 row in Set (0.00 sec)
3.2. Multi-line annotations
3.2.1. No spaces between the content and the comment
Examples such as the following:
Select @schema
/* which schema
how to get schema*/;
Mysql> Select @schema
-/*which Schema
/*> how to get schema*/;
+---------+
| @schema |
+---------+
| NULL |
+---------+
1 row in Set (0.00 sec)
3.2.2. There is a space between the "* *" and the comment content
Mysql> Select @schema
-/*which Schema
/*> how to get schema */;
+---------+
| @schema |
+---------+
| NULL |
+---------+
1 row in Set (0.00 sec)
3.2.2. "/*" with a space between the comment contents
Mysql> Select @schema
-*/* which schema
/*> how to get schema*/;
+---------+
| @schema |
+---------+
| NULL |
+---------+
1 row in Set (0.00 sec)
4, "/*! */"Comment
hide MySQL-specific keywords, comments with "/*!" Instead of beginning with "/*". MySQL looks inside this special type of comment and uses these keywords, but other database servers ignore these keywords as part of the comment. This helps to write code that takes advantage of MySQL-specific functionality when MySQL executes, and that code can be used for other database servers without modification.
For example:
/*!50001 DROP TABLE IF EXISTS ' count_yysbh ' */;
50001 means that if the database version is 5.00.01 or later, "DROP TABLE if EXISTS ' COUNT_YYSBH '" will not be executed.
Summary of comments for MySQL server