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