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');
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 '列的注释内容'; -- 注意:字段名和字段类型照写就行
ALTER TABLE users ADD name varchar(20);
alter table users modify name varchar(20) not null comment '用户名';
show full columns from users;
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!