Comment usage in MySQL

Source: Internet
Author: User

Transferred from: http://wenku.baidu.com/view/2a54e7892cc58bd63186bd8f.html

In the MySQL database ,
The comment for a field or column is added with the attribute comment .

In the script that creates the new table,
You can add a comment by adding the Comment property to the field definition script .

The sample code is as follows:
CREATE TABLE Test (
ID int NOT NULL default 0 comment ' user id '
)

If it's a table that's already been built,
You can also add comments by modifying the field's command and then adding the comment attribute definition.

The sample code is as follows:
ALTER TABLE test
Change column ID ID int. NOT NULL default 0 comment ' test table ID '


View comments for all fields of an existing table?
You can use the command:show full columns from table to view,
Examples are as follows:
Show full columns from test;

1Create a tableWrite a comment when you
CREATE TABLE Test1
(
field_name int comment 'FieldThe comments'
) comment= 'TableThe comments';

2Modify TableThe comments
ALTER TABLE test1 Comment 'ModifyComments on the table after';

3Modifying FieldsThe comments
ALTER TABLE test1 Modify column field_name int comment 'ModifyAfter the field comment';
--Note: Field names and field types are writtenJust do it.

4View Table CommentsThe method
--In the generated SQLStatementSee
Show CREATE table test1;
--in the table of meta-data
Use INFORMATION_SCHEMA;
SELECT * from TABLES where table_schema= ' my_db ' and table_name= ' test1 ' \g

5View Field CommentsThe method
--show
Show full columns from test1;
--in the table of meta-data
SELECT * from COLUMNS where table_schema= ' my_db ' and table_name= ' test1 ' \g

Comment usage in MySQL

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.