mysql查看和修改注释,这里创建一张学生表来进行说明。
一.如何创建表
创建表的时候写注释。
create table test1 ( field_name int comment '字段的注释' )comment='表的注释';
创建学生表示例如下:
二.修改表的注释和创建
alter table test1 comment '修改后的表的注释';
示例代码如下:
ALTER TABLE `student` COMMENT '学生表2.0';
结果如下图所示:
三. 修改字段的注释
扫描二维码关注公众号,回复:
310819 查看本文章
alter table test1 modify column field_name int comment '修改后的字段注释';
注意:字段名和字段类型照写就行
修改示例如下:
ALTER TABLE `student` MODIFY COLUMN `id` COMMENT '学号';
查看字段的信息,代码如下:
SHOW FULL COLUMNS FROM `student`;
结果如图所示:
四.查看表注释的方法
1.在生成的SQL语句中看
show create table test1;
如查看student表的注释
SHOW CREATE TABLE `student`
2.在元数据的表里面看
use information_schema; select * from TABLES where TABLE_SCHEMA='my_db' and TABLE_NAME='test1'
或
select * from information_schema.tables where table_schema='my_db' and table_name='test1';
五.查看字段注释的方法
1.show方法
show full columns from test1;
2.在元数据的表里面看
select * from COLUMNS where TABLE_SCHEMA='my_db' and TABLE_NAME='test1'
或
select * from information_schema.columns where table_schema='my_db' and table_name='test1'
六.查看表的约束信息
mysql 客户端提供的describe table_name命令,只能显示一个表的primary key和foreign key。
mysql所有有关数据schema的信息都保存在INFORMATION_SCHEMA这个database instance里面。其中的TABLE_CONSTRAINTS和KEY_COLUMN_USAGE表,保存了表的所有key信息。
TABLE_CONSTRAINTS,保存了表的约束条件,而KEY_COLUMN_USAGE保存了表的详细column对应的约束条件信息。
示例如下:
select * from information_schema.TABLE_CONSTRAINTS t where t.table_name = 'student';
select * from information_schema.KEY_COLUMN_USAGE t where t.table_name = 'student' and t.CONSTRAINT_NAME = 'PRIMARY';
use information_schema; select * from TABLES where TABLE_SCHEMA='my_db' and TABLE_NAME='test1'或
select * from information_schema.tables where table_schema='my_db' and table_name='test1';
五.查看字段注释的方法
1.show方法
show full columns from test1;
2.在元数据的表里面看
select * from COLUMNS where TABLE_SCHEMA='my_db' and TABLE_NAME='test1'
或
select * from information_schema.columns where table_schema='my_db' and table_name='test1'
1.show方法
show full columns from test1;
2.在元数据的表里面看
select * from COLUMNS where TABLE_SCHEMA='my_db' and TABLE_NAME='test1'
或
select * from information_schema.columns where table_schema='my_db' and table_name='test1'六.查看表的约束信息
mysql 客户端提供的describe table_name命令,只能显示一个表的primary key和foreign key。
mysql所有有关数据schema的信息都保存在INFORMATION_SCHEMA这个database instance里面。其中的TABLE_CONSTRAINTS和KEY_COLUMN_USAGE表,保存了表的所有key信息。
TABLE_CONSTRAINTS,保存了表的约束条件,而KEY_COLUMN_USAGE保存了表的详细column对应的约束条件信息。
示例如下:
select * from information_schema.TABLE_CONSTRAINTS t where t.table_name = 'student';
select * from information_schema.TABLE_CONSTRAINTS t where t.table_name = 'student';
select * from information_schema.KEY_COLUMN_USAGE t where t.table_name = 'student' and t.CONSTRAINT_NAME = 'PRIMARY';
参考文章:http://jingyan.baidu.com/article/f3e34a12835fa9f5ea65354e.html