In mysql, you can use the ALTER TABLE statement to add fields and comments. This statement can add or modify a data table. The syntax is "ALTER TABLE table name ADD field name type COMMENT 'comment content';"; ADD is used For adding data, COMMENT is used to represent comment content.
The operating environment of this tutorial: windows10 system, mysql8.0.22 version, Dell G3 computer.
Add field keyword alter Comment keyword comment
The role of ALTER TABLE
ALTER TABLE command is used to add, delete or change columns in existing data tables.
The syntax is
ALTER TABLE 表名 ADD 字段名 varchar(20) COMMENT '注释内容';
No comments, just remove the comment
Examples of adding fields are as follows:
alter table user add COLUMN new1 VARCHAR(20) DEFAULT NULL; //增加一个字段,默认为空 alter table user add COLUMN new2 VARCHAR(20) NOT NULL; //增加一个字段,默认不能为空
If the table has already been built, you can use The command to modify the field, plus the comment attribute.
For example:
alter table users modify name varchar(20)not null comment ‘用户名’;
Here users is the table name, name is the field name, varchar (20) is the type, and not null is the constraint.
Recommended learning: mysql video tutorial
The above is the detailed content of How to add fields and comments in mysql. For more information, please follow other related articles on the PHP Chinese website!