如何在 MySQL 中添加注释?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/9098655/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How can I add comments in MySQL?
提问by amir amir
I want to add comment in SQL code. How can I do this? I'm using MySQL.
我想在 SQL 代码中添加注释。我怎样才能做到这一点?我正在使用 MySQL。
回答by Martti Laine
Several ways:
几种方式:
# Comment
-- Comment
/* Comment */
Remember to put the space after --
.
记得在 之后放空格--
。
See the documentation.
请参阅文档。
回答by Dinesh Gehlot
"A comment for a column can be specified with the COMMENT
option. The comment is displayed by the SHOW CREATE TABLE
and SHOW FULL COLUMNS
statements. This option is operational as of MySQL 4.1. (It is allowed but ignored in earlier versions.)"
“可以使用COMMENT
选项指定列的注释。注释由SHOW CREATE TABLE
andSHOW FULL COLUMNS
语句显示。此选项从 MySQL 4.1 开始运行。(在早期版本中允许但被忽略。)”
As an example
举个例子
--
-- Table structure for table 'accesslog'
--
CREATE TABLE accesslog (
aid int(10) NOT NULL auto_increment COMMENT 'unique ID for each access entry',
title varchar(255) default NULL COMMENT 'the title of the page being accessed',
path varchar(255) default NULL COMMENT 'the local path of teh page being accessed',
....
) TYPE=MyISAM;
回答by fivedigit
You can use single line comments:
您可以使用单行注释:
-- this is a comment
# this is also a comment
Or a multiline comment:
或多行注释:
/*
multiline
comment
*/
回答by Bort
回答by Mr Coder
Three types of commenting are supported
支持三种评论类型
Hash base single line commenting using #
Select * from users ; # this will list users
- Double Dash commenting using --
Select * from users ; -- this will list users
散列基单行注释使用#
Select * from users ; # this will list users
- 双破折号评论使用 -
Select * from users ; -- this will list users
Note : Its important to have single white space just after --
注意:紧随其后的单个空格很重要 -
3) Multi line commenting using /* */
3) 多行注释使用 /* */
Select * from users ; /* this will list users */
回答by rivethead_
/* comment here */
here is an example: SELECT 1 /* this is an in-line comment */ + 1;
这是一个例子: SELECT 1 /* this is an in-line comment */ + 1;