如何在MySQL中添加注释?

时间:2023-01-24 23:11:46

I want to add comment in SQL code. How can I do this? I'm using MySQL.

我想在SQL代码中添加注释。我该怎么做呢?我使用的是MySQL。

6 个解决方案

#1


156  

Several ways:

几个方面:

# Comment
-- Comment
/* Comment */

See the docs.

看文档。

#2


17  

"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表显示,并显示完整列语句。这个选项的操作方式是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;

#3


13  

You can use single line comments:

您可以使用单行注释:

-- this is a comment
# this is also a comment

Or a multiline comment:

或多行注释:

/*
   multiline
   comment
*/

#4


3  

From here you can use

从这里你可以使用

#  For single line comments
-- Also for single line, must be followed by space/control character
/*
    C-style multiline comment
*/

#5


1  

Three types of commenting are supported

支持三种类型的注释。

  1. Hash base single line commenting using #

    使用#注释哈希基单行

    Select * from users ; # this will list users
    
    1. Double Dash commenting using --
    2. 使用-

    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 */

#6


0  

/* comment here */ 

here is an example: SELECT 1 /* this is an in-line comment */ + 1;

这里有一个示例:SELECT 1 /*这是一个内行注释*/ + 1;

http://dev.mysql.com/doc/refman/5.0/en/comments.html

http://dev.mysql.com/doc/refman/5.0/en/comments.html

#1


156  

Several ways:

几个方面:

# Comment
-- Comment
/* Comment */

See the docs.

看文档。

#2


17  

"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表显示,并显示完整列语句。这个选项的操作方式是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;

#3


13  

You can use single line comments:

您可以使用单行注释:

-- this is a comment
# this is also a comment

Or a multiline comment:

或多行注释:

/*
   multiline
   comment
*/

#4


3  

From here you can use

从这里你可以使用

#  For single line comments
-- Also for single line, must be followed by space/control character
/*
    C-style multiline comment
*/

#5


1  

Three types of commenting are supported

支持三种类型的注释。

  1. Hash base single line commenting using #

    使用#注释哈希基单行

    Select * from users ; # this will list users
    
    1. Double Dash commenting using --
    2. 使用-

    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 */

#6


0  

/* comment here */ 

here is an example: SELECT 1 /* this is an in-line comment */ + 1;

这里有一个示例:SELECT 1 /*这是一个内行注释*/ + 1;

http://dev.mysql.com/doc/refman/5.0/en/comments.html

http://dev.mysql.com/doc/refman/5.0/en/comments.html