獲取資料庫表字段名,長度,型別,備註等資訊
阿新 • • 發佈:2018-12-10
獲取資料庫表的所有欄位的資訊
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編寫,內容有可能呼叫變動或者無法使用,請各位注意一下!