How can I add comments in MySQL?

143

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

This question is tagged with mysql database comments

~ Asked on 2012-02-01 15:39:22

The Best Answer is


239

Several ways:

# Comment
-- Comment
/* Comment */

Remember to put the space after --.

See the documentation.

~ Answered on 2012-02-01 15:40:38


25

"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.)"

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;

~ Answered on 2012-02-01 16:46:00


Most Viewed Questions: