Two adding methods: 1. Use the "CREATE TABLE" statement and the comment keyword to comment the column when creating the table, the syntax is "create table name (column name field type comment 'column comment content') ;"; 2. Use the "ALTER TABLE" statement and the comment keyword to comment the column when modifying the table. The syntax is "alter table table name modify column column name data type comment 'column comment content';".
The operating environment of this tutorial: windows7 system, mysql8 version, Dell G3 computer.
Mysql method of adding comments to columns (fields)
In the MySQL database, comments on fields or columns are added using the attribute comment . There are two ways to add.
1. Use the CREATE TABLE statement and the comment keyword to comment the columns when creating the table
Syntax:
create 表名 ( 列名 字段类型 comment '列的注释内容' );
Example: Create the users table , there is an id field in it, add a comment to the field
create table users(id int(11) primary key comment '用户id');## After the addition is completed, look at the field comment:
show full columns from users;
2. Use the ALTER TABLE statement and comment keyword to comment the columns when modifying the table
Syntax:alter table 表名 modify column 列名 数据类型 comment '列的注释内容'; -- 注意:字段名和字段类型照写就行Example: In the users table, add a name field
ALTER TABLE users ADD name varchar(20);View the table structure Add comments to the name field
alter table users modify name varchar(20) not null comment '用户名';After the addition is completed, take a look at the field comments:
show full columns from users;[Related recommendations:
mysql Video tutorial】
The above is the detailed content of How to add comments to columns (fields) in mysql. For more information, please follow other related articles on the PHP Chinese website!