【发布时间】:2012-02-24 07:12:28
【问题描述】:
我想在 SQL 代码中添加注释。我怎样才能做到这一点?我正在使用 MySQL。
【问题讨论】:
我想在 SQL 代码中添加注释。我怎样才能做到这一点?我正在使用 MySQL。
【问题讨论】:
【讨论】:
-- 之后
"可以使用COMMENT 选项指定列的注释。注释由SHOW CREATE TABLE 和SHOW FULL COLUMNS 语句显示。此选项从 MySQL 4.1 开始可操作。(在 MySQL 4.1 中允许但忽略较早的版本。)”
举个例子
--
-- 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;
【讨论】:
您可以使用单行 cmets:
-- this is a comment
# this is also a comment
或多行注释:
/*
multiline
comment
*/
【讨论】:
来自here你可以使用
# For single line comments
-- Also for single line, must be followed by space/control character
/*
C-style multiline comment
*/
【讨论】:
支持三种类型的评论
使用 # 散列单行注释
Select * from users ; # this will list users
Select * from users ; -- this will list users
注意:在 -- 之后有一个空格很重要
3) 使用 /* */ 进行多行注释
Select * from users ; /* this will list users */
【讨论】:
/* comment here */
这里是一个例子:SELECT 1 /* this is an in-line comment */ + 1;
【讨论】: