獲取數據庫表的所有字段的信息
select * from information_schema.columns where table_name = '表名'
獲取數據庫表字段名,長度,類型,備註,是否能空
select column_name,COLUMN_TYPE,IS_NULLABLE,COLUMN_COMMENT from information_schema.columns where table_name= '表名'
提供常用的information_schema.columns的值
1、table_catalog :不管是table | view 這個列的值總是def
2、table_schema :表 | 視圖所在的數據庫名
3、table_name :表名 | 視圖名
4、column_name :列名
5、column_default :列的默認值
6、is_nullable :是否可以取空值
7、data_type :列的數據類型
8、character_maximum_length :列的最大長度(這列只有在數據類型爲char | varchar 時纔有意義)
9、column_type :列類型這個類型比data_type列所指定的更加詳細,如data_type 是int 而column_type 就有可以能是int(11)
10、column_key :列上的索引類型 主鍵-->PRI | 唯一索引 -->UNI 一般索引 -->MUL
例子:
select table_catalog,table_schema,table_name,column_name,column_default,is_nullable,data_type,character_maximum_length,
column_type,column_key from information_schema.columns where table_name = 'ac_admin'
說明:該文章如有侵權,請聯繫我!該文章只供參考,有問題請各位自己擔當哈!!在文章是在20180917編寫,內容有可能調用變動或者無法使用,請各位注意一下!