在mysql中,可以利用“ALTER TABLE”語句和“column”關(guān)鍵字來修改字段注釋,語法“alter table 表名 modify column 字段名稱 字段類型 comment '修改后的字段注釋';”。
本教程操作環(huán)境:windows7系統(tǒng)、mysql8版本、Dell G3電腦。
在MySQL數(shù)據(jù)庫中, 字段或列的注釋是用屬性comment來添加。
創(chuàng)建新表的腳本中, 可在字段定義腳本中添加comment屬性來添加注釋。
示例代碼如下:
create table test( id int not null default 0 comment '用戶id' )
如果是已經(jīng)建好的表, 也可以用修改字段的命令,然后加上comment屬性定義,就可以添加上注釋了。
示例代碼如下:
alter table test modify column id int not null default 0 comment '測試表id'
查看已有表的所有字段的注釋呢?
可以用命令:show full columns from table
來查看, 示例如下:
show full columns from test;
創(chuàng)建表的時候?qū)懽⑨?/h3>
create table test1 ( field_name int comment '字段的注釋' )comment='表的注釋';
修改表的注釋
alter table 表名 comment '修改后的表的注釋';
修改字段的注釋
alter table 表名 modify column 字段名稱 字段類型 comment '修改后的字段注釋'; -- 注意:字段名和字段類型照寫就行
查看表注釋的方法
-- 在生成的SQL語句中看 show create table test1; -- 在元數(shù)據(jù)的表里面看 use information_schema; select * from TABLES where TABLE_SCHEMA='my_db' and TABLE_NAME='test1' G
查看字段注釋的方法
-- show show full columns from test1; -- 在元數(shù)據(jù)的表里面看 select * from COLUMNS where TABLE_SCHEMA='my_db' and TABLE_NAME='test1' G
【