Home >Database >Mysql Tutorial >How to add comments when creating a table in MySQL
In mysql, you can use the "create table" statement and the comment keyword to add comments when creating a table. The syntax is "create table table name (field name field type comment 'field comment') comment=' Table comment ';'.
The operating environment of this tutorial: windows7 system, mysql8 version, Dell G3 computer.
In the MySQL database, comments on tables or fields (columns) are added using the attribute comment.
In the script that creates a new table, you can add comments by adding the comment attribute in the field definition script.
MySQL table creation statement adding comments
1. Table creation comments
Syntax:
create table 表名 ( 字段名 字段类型 comment '字段的注释' ) comment='表注释';
Example
CREATE TABLE student( id INT PRIMARY KEY AUTO_INCREMENT COMMENT '学号', name VARCHAR(200) COMMENT '姓名', age int COMMENT '年龄' ) COMMENT='学生信息'
2. Modify comments
Modify table comments-ALTER TABLE student COMMENT 'Student table';
Modify column comments-ALTER TABLE student MODIFY COLUMN name VARCHAR(100) COMMENT 'name';
SELECT table_name,table_comment FROM information_schema.tables WHERE table_schema = '所在的db' AND table_name ='表名groups'
SHOW FULL COLUMNS FROM groups
-- This can be used to search for a name or a certain name based on conditions Data type column information: for example
SHOW FULL COLUMNS FROM tableName WHERE FIELD = 'add_time' OR TYPE LIKE '%date%' -- 查看tableName表中列名是add_time的或类型是date的列 SELECT column_name, column_comment FROM information_schema.columns WHERE table_schema ='db' AND table_name = 'groups' SHOW CREATE TABLE communication_group
[Related recommendations: mysql video tutorial]
The above is the detailed content of How to add comments when creating a table in MySQL. For more information, please follow other related articles on the PHP Chinese website!