mysql view and modify comments

        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`
2. Look in the table of metadata
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';
 
5. How to view field annotations

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
        The describe table_name command provided by the mysql client can only display the primary key and foreign key of a table.
        All mysql information about the data schema is stored in the database instance INFORMATION_SCHEMA. The TABLE_CONSTRAINTS and KEY_COLUMN_USAGE tables store all key information of the table.
        TABLE_CONSTRAINTS saves the constraints of the table, and KEY_COLUMN_USAGE saves the constraint information corresponding to the detailed column of the table.
        An example is as follows:
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';
2. Look in the table of metadata
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';
 
5. How to view field annotations

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'

 

  5. How to view field annotations

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
        The describe table_name command provided by the mysql client can only display the primary key and foreign key of a table.
        All mysql information about the data schema is stored in the database instance INFORMATION_SCHEMA. The TABLE_CONSTRAINTS and KEY_COLUMN_USAGE tables store all key information of the table.
        TABLE_CONSTRAINTS saves the constraints of the table, and KEY_COLUMN_USAGE saves the constraint information corresponding to the detailed column of the table.
        An example is as follows:
select * from information_schema.TABLE_CONSTRAINTS t where t.table_name = 'student';
        The describe table_name command provided by the mysql client can only display the primary key and foreign key of a table. All mysql information about the data schema is stored in the database instance INFORMATION_SCHEMA. The TABLE_CONSTRAINTS and KEY_COLUMN_USAGE tables store all key information of the table. TABLE_CONSTRAINTS saves the constraints of the table, and KEY_COLUMN_USAGE saves the constraint information corresponding to the detailed column of the table. An example is as follows:
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

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326861155&siteId=291194637