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

Showing database table names and their column numbers

所以我想看看我的每个 table 在数据库库中有多少列。

我用

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

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

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

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

您可以使用 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';

已解决:

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