mysql information_schema

本文介绍了如何使用SQL查询MySQL数据库中的表结构信息,包括table_schema,table_name,字段名、数据类型(如varchar,decimal)、默认值、是否可为空以及字段约束和备注。
摘要由CSDN通过智能技术生成
mysql表信息查询
-- mysql表信息查询
select table_schema,
       table_name,
       table_comment
from information_schema.tables
where table_schema = 'table_schema';
mysql表字段查询
-- mysql表字段查询
select table_schema   as '实例',
       table_name     as '表名',
       column_name    as '字段名',
       case data_type
           when 'varchar' then concat(data_type, '(', character_maximum_length, ')')
           when 'decimal' then concat(data_type, '(', numeric_precision, ',', numeric_scale, ')')
           else data_type
           end        as '数据类型',
       column_default as '默认值',
       is_nullable    as '是否可为空',
       column_key     as '约束',
       column_comment as '备注'
from information_schema.columns
where columns.table_schema = 'table_schema'
  and table_name = 'table_name'
order by ordinal_position;
-- mysql表字段查询
select table_schema,
       table_name,
       column_name,
       case data_type
           when 'varchar' then concat(data_type, '(', character_maximum_length, ')')
           when 'decimal' then concat(data_type, '(', numeric_precision, ',', numeric_scale, ')')
           else data_type
           end as data_type,
       column_default,
       is_nullable,
       column_key,
       column_comment
from information_schema.columns
where columns.table_schema = 'table_schema'
  and table_name = 'table_name'
order by ordinal_position;
  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值