information_schema.columns 学习

每一个表中的每一列都会在information_schema.columns表中对应一行

1、informaiton_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

 

2、例子

查看tempdb 库中的列信息

 

select 
    table_schema,table_name,column_name,column_type,column_default,is_nullable,column_key

from
    information_schema.columns

where table_schema='tempdb';


+--------------+------------+-------------+-------------+----------------+-------------+------------+
| table_schema | table_name | column_name | column_type | column_default | is_nullable | column_key |
+--------------+------------+-------------+-------------+----------------+-------------+------------+
| tempdb       | t          | x           | int(11)     | NULL           | NO          | PRI        |
| tempdb       | t          | y           | varchar(32) | hello world... | NO          | MUL        |
| tempdb       | t2         | id          | int(11)     | NULL           | NO          | PRI        |
| tempdb       | t2         | age         | int(11)     | 0              | NO          | PRI        |
| tempdb       | t2         | name        | varchar(10) | NULL           | YES         |            |
| tempdb       | v_t        | x           | int(11)     | 0              | NO          |            |
| tempdb       | v_t        | y           | varchar(32) | hello world... | NO          |            |
+--------------+------------+-------------+-------------+----------------+-------------+------------+

 

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值