获取数据库表字段名,长度,类型,备注等信息

获取数据库表的所有字段的信息

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编写,内容有可能调用变动或者无法使用,请各位注意一下!

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章