mysql view and modify comments, create a student table here to explain.
1. How to create a table
Write a comment when creating the table.
create table test1 ( field_name int comment 'Comment of the field' )comment='Comment of the table';
Create a student representation as follows:
2. Modify the annotation and creation of the table
alter table test1 comment 'The comment of the modified table';
The sample code is as follows:
ALTER TABLE `student` COMMENT 'student table 2.0';
The result is shown below:
3. Modify the comment of the field
alter table test1 modify column field_name int comment 'Modified field comment';
Note: Field names and field types are just as written
The modified example is as follows:
ALTER TABLE `student` MODIFY COLUMN `id` COMMENT '学号';
To view the information of the field, the code is as follows:
SHOW FULL COLUMNS FROM `student`;
The result is shown in the figure:
4. How to view table comments
1. Look in the generated SQL statement
show create table test1;
Such as viewing the comments of the student table
SHOW CREATE TABLE `student`
use information_schema; select * from TABLES where TABLE_SCHEMA='my_db' and TABLE_NAME='test1'
select * from information_schema.tables where table_schema='my_db' and table_name='test1';
1.show method
show full columns from test1;
2. Look in the table of metadata
select * from COLUMNS where TABLE_SCHEMA='my_db' and TABLE_NAME='test1'
or
select * from information_schema.columns where table_schema='my_db' and table_name='test1'
select * from information_schema.TABLE_CONSTRAINTS t where t.table_name = 'student';
select * from information_schema.KEY_COLUMN_USAGE t where t.table_name = 'student' and t.CONSTRAINT_NAME = 'PRIMARY';
use information_schema; select * from TABLES where TABLE_SCHEMA='my_db' and TABLE_NAME='test1'or
select * from information_schema.tables where table_schema='my_db' and table_name='test1';
1.show method
show full columns from test1;
2. Look in the table of metadata
select * from COLUMNS where TABLE_SCHEMA='my_db' and TABLE_NAME='test1'
or
select * from information_schema.columns where table_schema='my_db' and table_name='test1'
1.show method
show full columns from test1;
2. Look in the table of metadata
select * from COLUMNS where TABLE_SCHEMA='my_db' and TABLE_NAME='test1'
or
select * from information_schema.columns where table_schema='my_db' and table_name='test1'
6. View the constraint information of the table
select * from information_schema.TABLE_CONSTRAINTS t where t.table_name = 'student';
select * from information_schema.TABLE_CONSTRAINTS t where t.table_name = 'student';
select * from information_schema.KEY_COLUMN_USAGE t where t.table_name = 'student' and t.CONSTRAINT_NAME = 'PRIMARY';
Reference article: http://jingyan.baidu.com/article/f3e34a12835fa9f5ea65354e.html