In the MySQL database, comments on fields or columns are added using the comment attribute.
In the script that creates a new table, you can add comments by adding the comment attribute in the field definition script.
The sample code is as follows:
create table test( id int not null default 0 comment ‘用户id’ )
If the table has been built, you can also use the command to modify the fields, and then add the comment attribute definition to add comments.
The sample code is as follows:
alter table test change column id id int not null default 0 comment ‘测试表id’
Related recommendations: "Navicat for mysql usage tutorial"
How about viewing the comments of all fields in an existing table?
You can use the command:
show full columns from table;
Examples are as follows:
show full columns from test;
1. Write comments when creating the table
create table test1 ( field_name int comment ‘字段的注释’ )comment=‘表的注释’;
2. Modify the comments of the table
alter table test1 comment ‘修改后的表的注释’;
3. Modify the comments of the field
alter table test1 modify column field_name int comment ‘修改后的字段注释’;
-Note: Just write the field name and field type exactly as they are
4. How to view the table comments
– Look at
show create table test1;
in the generated SQL statement – Look at
use information_schema; select * from TABLES where TABLE_SCHEMA=‘my_db’ and TABLE_NAME=‘test1’ \G
in the metadata table 5. How to view field comments
–show show full columns from test1;
– Look at the metadata table Look inside
select * from COLUMNS where TABLE_SCHEMA=‘my_db’ and TABLE_NAME=‘test1’ \G
When using the tool Navicat, it is easier to add comments.
Right-click to select the table that needs to be commented. You can see the comment COMMENT under DDL in the object information.
Right-click and select "Design Table", you can see the comments below, click "Add".
The above is the detailed content of How to display field comments in Navicat. For more information, please follow other related articles on the PHP Chinese website!