1、创建带解释的表
create table test_table( t_id int(11) primary key auto_increment comment '设置主键自增',t_name varchar(64) comment '列注释') comment='表注释';
2、修改表注释
alter table test_table comment '修改表注释';
3、查看表注释(免费学习视频教程分享:mysql视频教程)
select table_comment from information_schema.tables where table_schema = 'test' and table_name = 'test_table'
4、添加列带注释
alter table test_table add t_age int(11) comment '年龄'
5、修改列名带注释
alter table test_table change t_age t_sex varchar(4) comment '性别'
6、修改列注释
alter table test_table modify column t_sex varchar(30) not null comment '男女'
注意:修改时要把该字段的完整定义写上,如字段类型、属性等。千万不要因为只是为了修改一个注释,而把该字段定义的其它属性给覆盖掉了。
7、删除列
alter table test_table drop column t_sex
8、查询表字段信息
show full columns from test_table
9、删除表
-- 单删drop table 表 -- 批删drop table 表1,表2,表3
10、批量修改某个字段值
update test_table set t_name = replace(t_name, 'test', 't')
如图:
例:运行前
运行后:
相关文章教程推荐:mysql教程
以上就是mysql为数据表及字段添加注释的详细内容。
