码迷,mamicode.com
首页 > 数据库 > 详细

mysql服务器的注释总结

时间:2014-09-25 12:16:29      阅读:180      评论:0      收藏:0      [点我收藏+]

标签:mysql服务器的注释总结

       MySQL允许在SQL 代码中使用注释。这对于阅读代码很有用处。MySQL服务器支持3种注释风格:

1、“#”注释

    以“#”字符开始,到所在行结尾的所有字符。

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)

    字符“#”和之后的字符之间,有无空格均可。

2、“--”+“空格”注释

    用两个短划线和一个空格注释;从这两个短划线到行的结束的所有内容都作为注释处理。以“--”字符开始,到所在行结尾的所有字符。特别注意:双破折号要求第2个破折号后面至少跟一个空格符(例如空格、tab、换行符等等)。

2.1.不带空格的情况:

mysql> select @schema; --which schema

+---------+

| @schema |

+---------+

| NULL    |

+---------+

1 row in set (0.00 sec)


    -> ;

ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ‘--which schema‘ at line 1

mysql>

2.2.带空格的情况:

mysql> select @schema; -- which schema

+---------+

| @schema |

+---------+

| NULL    |

+---------+

1 row in set (0.00 sec)

3、“/*  */”单行或者多行注释   

    从“/*”字符开始,到“*/”结尾。结束序列不一定在同一行中,因此该语法允许注释跨越多行。

3.1.单行注释

3.1.1.和注释内容之间无空格

mysql> select @schema; /*which schema*/

+---------+

| @schema |

+---------+

| NULL    |

+---------+

1 row in set (0.00 sec)

3.1.2.“/*”和注释内容之间有空格

mysql> select @schema; / *which schema*/

+---------+

| @schema |

+---------+

| NULL    |

+---------+

1 row in set (0.01 sec)


    -> ;

ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ‘/ *which schema*/‘ at line 1

3.1.3.“*/”和注释内容之间有空格

mysql> select @schema; /*which schema */

+---------+

| @schema |

+---------+

| NULL    |

+---------+

1 row in set (0.00 sec)

3.2.多行注释

3.2.1.和注释内容之间无空格

    诸如如下例子:

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.“*/”和注释内容之间有空格

mysql> select @schema 

    -> /*which schema

   /*> how to get schema */;

+---------+

| @schema |

+---------+

| NULL    |

+---------+

1 row in set (0.00 sec)

3.2.2.“/*”和注释内容之间有空格

mysql> select @schema 

    -> /* which schema

   /*> how to get schema*/;

+---------+

| @schema |

+---------+

| NULL    |

+---------+

1 row in set (0.00 sec)

    综述,“/* */”单行注释内容时,“/*”和注释内容之间不能有空格;

          “/* */”多行注释内容时,“/* */”和注释内容之间有无空格均可。

4、“/*! */”注释 

    隐藏MySQL特有的关键字,注释以“/ * !”而不是以“ / *”起头。MySQL查看这种特殊类型注释的内部并使用这些关键字,但其他数据库服务器将这些关键字作为注释的一部分忽略。这样有助于编写由MySQL执行时利用MySQL特有功能的代码,而且该代码也可以不用修改就用于其他数据库服务器。

        例如:

/*!50001 DROP TABLE IF EXISTS `count_yysbh`*/;

        50001表示假如数据库版本是5.00.01以上版本,“DROP TABLE IF EXISTS `count_yysbh`”才会被执行。


mysql服务器的注释总结

标签:mysql服务器的注释总结

原文地址:http://gfsunny.blog.51cto.com/990565/1557954

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!