mysql_注释

MYSQL注释

注释

为啥添加注释

字段有时候一多的话,会很麻烦,特别是我这种英语小白,用英文做字段,看下来全部字段满眼懵逼.所以添加上备注是最方便的

如何给字段添加注释

创建表的时候写注释

create table test1 ( 
    field_name int comment '字段的注释' 
)comment='表的注释'; 

修改已经创建好表的注释

alter table table_name comment '注释内容';//修改的是表注释
alter table table_name modify column field_name int comment'注释内容';//修改表中的字段注释1
alter table table_name modify column field_name varchar(255) comment'注释内容';//修改表中的字段注释2

上面2种不同的修改方法,注意类型要按照类型(长度)的方式,如果长度有的话;

如何查看注释

show full columns from table_name;//查看注释
//sql语句查看
show  create  table  table_name; 

延伸

只查询列名和类型和注释,方便修改注释
select column_name, column_type, column_comment from information_schema.columns where table_schema ='数据库名称' and table_name = '表名' ;

同样,也可以查看column_type等字段
只需要替换2个引号中间的即可,db为数据库名称,tablename为表名称

查看数据库下所有表名
select table_name from information_schema.tables where table_schema='数据库名称' and table_type='base table';

猜你喜欢

转载自blog.csdn.net/wayrboy/article/details/81484636