How to add comments in MySQL?

I want to add a comment to the SQL code. How can i do this? I am using MySQL.

+114
comments database mysql
Feb 01 '12 at 15:39
source share
6 answers

Several ways:

# Comment -- Comment /* Comment */ 

Remember to put a space after -- .

See the documentation .

+198
Feb 01 2018-12-01T00:
source share

"You can specify a comment for a column using the COMMENT parameter. The comment is displayed by the SHOW CREATE TABLE and SHOW FULL COLUMNS statements. This parameter works with MySQL 4.1 (it is allowed but ignored in earlier versions.)"

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; 
+20
Feb 01 2018-12-01T00:
source share

You can use single line comments:

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

Or a multi-line comment:

 /* multiline comment */ 
+15
Feb 01 2018-12-01T00:
source share

From here you can use

 # For single line comments -- Also for single line, must be followed by space/control character /* C-style multiline comment */ 
+3
Feb 01 '12 at 15:41
source share

Three types of comments are supported:

  • Hashbase single row combination using #

     Select * from users ; # this will list users 
    1. Commenting on Double Dash using -

Select * from users ; -- this will list users

Note. It’s important that immediately after it there is one empty space -

3) Multi-line commenting using / * * /

 Select * from users ; /* this will list users */ 
+1
Oct 08 '15 at 10:39
source share
 /* comment here */ 

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

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

0
Feb 01 '12 at 15:41
source share



All Articles