显示数据库表名称及其列号

时间:2017-11-12 17:21:03

标签: mysql database database-schema

所以我想查看数据库库中每个表的列数。

我用

select * from information_schema.tables where table_schema = 'library';

查看名称,我可以看到行数,但是,我不知道如何让它显示列。事实上我只需要姓名和列号,但我不知道如何要求查看姓名。我试过了

show tables from information_schema.tables where table_schema = 'library';

但我猜这绝对是错误的,因为错误也会出现

2 个答案:

答案 0 :(得分:1)

解决了:

SELECT table_name, COUNT(*) FROM information_schema.columns WHERE table_schema = 'Library' Group by table_name;

答案 1 :(得分:0)

您可以使用information_schema.columns

select t.*, c.*
from information_schema.tables t join
     information_schema.columns c
     on t.table_schema = c.table_schema and t.table_name = c.table_name
where t.table_schema = 'library';
相关问题