1. 程式人生 > 其它 >Mysql--表註釋,欄位註釋

Mysql--表註釋,欄位註釋

information_schema資料庫是MySQL資料庫自帶的資料庫,裡面存放的MySQL資料庫所有的資訊,包括資料表、資料註釋、資料表的索引、資料庫的許可權等等。

1、新增表、欄位註釋

create table test
(
  cluster_id varchar(40) NOT NULL COMMENT '''叢集id''',
  cluster_name varchar(100) NOT NULL COMMENT '''叢集名''',
  PRIMARY KEY (`cluster_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT = '
叢集資訊';

2、修改表註釋

alter table test COMMENT '叢集資訊2';

3、修改欄位註釋(修改時要把該欄位的完整定義寫上,如欄位型別、屬性等,不能因修改註釋,而把該欄位定義的其它屬性給覆蓋掉了)

alter table test modify column cluster_id varchar(40) NOT NULL COMMENT '''叢集id2''',

4、查詢

#檢視單個表的欄位註釋
show full columns from test;

#檢視所有表的表註釋
select table_name 表名,
table_comment 表註釋 
from information_schema.tables where table_schema = 'DB_name'; #查看錶的所有欄位註釋 select column_name 欄位名, column_comment 欄位註釋, column_type 欄位型別, column_key 約束 from information_schema.columns where table_schema='DB_name' and table_name='test'; #檢視所有表的表註釋及欄位註釋 SELECT a.table_name 表名, a.table_comment 表說明, b.COLUMN_NAME 欄位名, b.column_comment 欄位說明, b.column_type 欄位型別, b.column_key 約束 FROM information_schema. TABLES a LEFT JOIN information_schema. COLUMNS b ON a.table_name
= b.TABLE_NAME WHERE a.table_schema = 'DB_name' ORDER BY a.table_name