Mysql 獲取表的comment 字段


 1 -- 查看獲取表內字段注釋:
 2 show full columns from tablename;
 3 -- 或是 
 4 show full fields from tablename;
 5 -- 或是,在元數據的表里面看
 6 Select COLUMN_NAME 列名, DATA_TYPE 字段類型, COLUMN_COMMENT 字段注釋
 7 from INFORMATION_SCHEMA.COLUMNS
 8 Where table_name = 'companies'##表名
 9 AND table_schema = 'testhuicard'##數據庫名
10 AND column_name LIKE 'c_name'##字段名
11 
12 
13 -- 2-1查看表注釋的方法:
14 show  create  table  tablename;
15 
16 -- 2-2獲取整個數據庫的所有表信息(包含表名,表注釋,表類型等等):
17 SELECT table_name, table_type, engine
18 FROM information_schema.tables
19 WHERE table_schema = 'db5' //table_schema是數據庫名
20 ORDER BY table_name DESC;
21 -- 該語句請求按逆向字母順序列出數據庫db5中的所有表,但僅顯示三種信息:表名,表類型,以及表引擎。
22 -- INFORMATION_SCHEMA是信息數據庫,其中保存着關於MySQL服務器所維護的所有其他數據庫的信息.
23 
24 SELECT TABLE_COMMENT FROM INFORMATION_SCHEMA.TABLES  WHERE TABLE_NAME = 'sh_goods' AND TABLE_SCHEMA = 'sh_shop';//獲取sh_shop 數據庫中 sh_goods 表 的注釋。
25 
26 -- 2-3獲取表注釋或是
27 -- 或者使用:
28 show table status;
29 --  Comment 就是表注釋。
30 
31 
32 
33 -- 拓展:
34 
35 -- 修改表的注釋:
36 alter table test1 comment '修改后的表的注釋';
37 
38 -- 修改字段的注釋:
39 alter table test1 modify column field_name int comment '修改后的字段注釋';  

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM