在mysql中,可以使用“create table”语句和comment关键字来在建表时添加注释,语法“create table 表名 (字段名 字段类型 comment '字段的注释')comment='表注释';”。
本教程操作环境:windows7系统、mysql8版本、dell g3电脑。
在mysql数据库中, 表或字段(列)的注释是用属性comment来添加。
创建新表的脚本中, 可在字段定义脚本中添加comment属性来添加注释。
mysql建表语句+添加注释
1、建表+注释
语法:
create table 表名 ( 字段名 字段类型 comment '字段的注释') comment='表注释';
示例
create table student( id int primary key auto_increment comment '学号', name varchar(200) comment '姓名', age int comment '年龄') comment='学生信息'
2.修改注释
修改表注释-alter table student comment '学生表';
修改列注释-alter table student modify column name varchar(100) comment '姓名';
select table_name,table_comment from information_schema.tables where table_schema = '所在的db' and table_name ='表名groups'
show full columns from groups
-- 这个可以按条件的去搜索某名字或某数据类型的列的信息:例如
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
【相关推荐:mysql视频教程】
以上就是mysql建表怎么添加注释的详细内容。