在MySQL數據庫中,
字段或列的註釋是用屬性comment來添加。
建立新表的腳本中,
可在字段定義腳本中添加comment屬性來添加註釋。
示例代碼以下:
create table test(
id int not null default 0 comment '用戶id'
)數據庫
若是是已經建好的表,
也能夠用修改字段的命令,而後加上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;測試
1 建立表的時候寫註釋
create table test1
(
field_name int comment '字段的註釋'
)comment='表的註釋';
2 修改表的註釋
alter table test1 comment '修改後的表的註釋';
3 修改字段的註釋
alter table test1 modify column field_name int comment '修改後的字段註釋';
--注意:字段名和字段類型照寫就行
4 查看錶註釋的方法
--在生成的SQL語句中看
show create table test1;
--在元數據的表裏面看
use information_schema;
select * from TABLES where TABLE_SCHEMA='my_db' and TABLE_NAME='test1' \G
5 查看字段註釋的方法
--show
show full columns from test1;
--在元數據的表裏面看
select * from COLUMNS where TABLE_SCHEMA='my_db' and TABLE_NAME='test1' \Gorm