mysql创建表的时候对字段和表添加COMMENT

351 阅读1分钟

创建新表的脚本中,可在字段定义脚本中添加comment属性来添加注释。

create table student_info (
  sno         int unsigned auto_increment comment '学号',
  name        varchar(50) not null comment '姓名',
  create_date date not null comment '创建时间',
  primary key(sno)
) engine=innodb default charset=utf8 comment '学生信息表';

如果是已经建好的表,也可以用修改字段的命令,然后加上comment属性定义,就可以添加上注释了。 这样表中的数据就有注解了

alter table test\
change column id id int not null default 0 comment '测试表id'

查看已有表的所有字段的注释呢?可以用命令:show full columns from table 来查看,
示例如下:

show full columns from test;

image.png

这个主要是方便后续的维护。