mysql表添加注釋的方法:1、在字段定義創(chuàng)建表腳本中添加comment屬性來(lái)添加注釋;2、使用修改字段的命令,然后加上comment屬性定義來(lái)添加上注釋即可。
本文操作環(huán)境:Windows7系統(tǒng),mysql5.5版,Dell G3電腦。
MySQL添加注釋
在數(shù)據(jù)庫(kù)設(shè)計(jì)中,我們是建議為數(shù)據(jù)庫(kù),數(shù)據(jù)表以及數(shù)據(jù)字段進(jìn)行添加注釋的,MySQL數(shù)據(jù)庫(kù)中, 字段或列的注釋是用屬性comment來(lái)添加。
創(chuàng)建新表的腳本中, 可在字段定義創(chuàng)建表腳本中添加comment屬性來(lái)添加注釋。
示例代碼如下:
1 create table test( 2 id int not null default 0 comment '用戶id' )
如果是已經(jīng)建好的表, 也可以用修改字段的命令,然后加上comment屬性定義,就可以添加上注釋了。
示例代碼如下:
1 alter table test 2 change column id id int not null default 0 comment '測(cè)試表id'
查看已有表的所有字段的注釋呢??
可以用命令:show full columns from table_name 來(lái)查看, 示例如下:
1 show full columns from test;
創(chuàng)建表的時(shí)候?qū)懽⑨?/h3>
1 create table test1 ( 2 field_name int comment '字段的注釋' 3 )comment='表的注釋';
修改表的注釋
1 alter table test1 comment '修改后的表的注釋';
修改字段的注釋
1 alter table test1 modify column field_name int comment '修改后的字段注釋'; 2 3 --注意:字段名和字段類型照寫就行
查看表注釋的方法
1 --在生成的SQL語(yǔ)句中看 2 show create table test1; 3 --在元數(shù)據(jù)的表里面看 4 use information_schema; 5 select * from TABLES where TABLE_SCHEMA='my_db' and TABLE_NAME='test1' G
查看字段注釋的方法
1 --show 2 show full columns from test1; 3 --在元數(shù)據(jù)的表里面看 4 select * from COLUMNS where TABLE_SCHEMA='my_db' and TABLE_NAME='test1' G
1 create table test1 ( 2 field_name int comment '字段的注釋' 3 )comment='表的注釋';
1 alter table test1 comment '修改后的表的注釋';
1 alter table test1 modify column field_name int comment '修改后的字段注釋'; 2 3 --注意:字段名和字段類型照寫就行
1 --在生成的SQL語(yǔ)句中看 2 show create table test1; 3 --在元數(shù)據(jù)的表里面看 4 use information_schema; 5 select * from TABLES where TABLE_SCHEMA='my_db' and TABLE_NAME='test1' G
1 --show 2 show full columns from test1; 3 --在元數(shù)據(jù)的表里面看 4 select * from COLUMNS where TABLE_SCHEMA='my_db' and TABLE_NAME='test1' G
推薦學(xué)習(xí):《mysql視頻教程》
? 版權(quán)聲明
文章版權(quán)歸作者所有,未經(jīng)允許請(qǐng)勿轉(zhuǎn)載。
THE END
喜歡就支持一下吧
相關(guān)推薦