Mysql中获取所有表和字段信息的方法

本文介绍了 Mysql中获取所有表和字段信息的方法

根据库名获取所有表的信息

information_schema.`TABLES`
select * from information_schema. tables where table_schema = '库名';
select * from information_schema. tables where table_schema = '库名';

根据库名获取所有的字段信息

information_schema.`COLUMNS`
select * from information_schema. columns

根据库名获取所有的表和表字段的基本信息

select c.table_schema             as '库名',
       t.table_name               as '表名',
       t.table_comment            as '表注释',
       c.column_name              as '列名',
       c.column_comment           as '列注释',
       c.ordinal_position         as '列的排列顺序',
       c.column_default           as '默认值',
       c.is_nullable              as '是否为空',
       c.data_type                as '数据类型',
       c.character_maximum_length as '字符最大长度',
       c.numeric_precision        as '数值精度(最大位数)',
       c.numeric_scale            as '小数精度',
       c.column_type              as 列类型,
       c.column_key 'KEY',
       c.extra                    as '额外说明'
  from information_schema. tables t
  left join information_schema. columns c
    on t.table_name = c.table_name
   and t.table_schema = c.table_schema
 where t.table_schema = 'dvmdm'
 order by c.table_name, c.ordinal_position;

查询某个字段在多个数据库表中的分布

select group_concat(table_schema separator ',') as '库名',
       group_concat(table_name separator ',') as '表名',
       column_name as '列名',
       group_concat(column_type separator ',') as '列类型',
       group_concat(column_comment separator ',') as '注释'
  from information_schema. columns
 where table_schema in ('库1', '库2', '库3')
 group by column_name
 order by group_concat(table_schema separator ','), column_name
上一篇 下一篇


推荐文章

评论
说点什么吧?

发表评论

取消回复
  最新文章