Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the purpose of 'comment' keyword in MySQL?

Tags:

comments

mysql

I have found there is the 'comment' keyword in MySQL.(not comment syntax like /* */, #)

But I do not know the reason why there is the 'comment' keyword.

If there is the following table, how could I use the 'comment'?

create table Employee(
    id int not null auto_increment,
    create_dt date comment 'the date when employee was hired'
    salary int comment 'salary in EUR',
    primary key (id)
) comment 'The employee table of company AA';
like image 536
dolgom Avatar asked Jul 20 '17 05:07

dolgom


People also ask

What is comment keyword SQL?

Purpose. Use the COMMENT statement to add a comment about a table, view, materialized view, or column into the data dictionary. To drop a comment from the database, set it to the empty string ' '. See Also: "Comments" for more information on associating comments with SQL statements and schema objects.

How do I comment out in MySQL?

Syntax Using /* and */ symbols In MySQL, a comment that starts with /* symbol and ends with */ and can be anywhere in your SQL statement. This method of commenting can span several lines within your SQL.

How do I select and comment in MySQL?

mysql> SELECT 1+1; # This comment continues to the end of line mysql> SELECT 1+1; -- This comment continues to the end of line mysql> SELECT 1 /* this is an in-line comment */ + 1; mysql> SELECT 1+ /* this is a multiple-line comment */ 1; Nested comments are not supported.


1 Answers

Comments are a way to store relevant information in the database itself. For example, putting a comment on a column will cause it to be displayed by the show create table and show full columns commands.

Note that this is different to what most people think of as comments in SQL - those are simply statements in scripts that are ignored after being parsed. They do not make their way into any metadata for later retrieval.

like image 158
paxdiablo Avatar answered Nov 10 '22 11:11

paxdiablo