kider 发表于 2007-8-8 19:59:00

计算数据库中所有表的记录数并输出.sql

适用于MySQL5.0以上版本。

1、构造SQL语句

sql>use information_schema;

sql>select concat("select """, TABLE_name,""", count(*) from ", TABLE_name," union all") from tables where TABLE_SCHEMA='huashan';

2、执行后输出:
select "BackUpinfo", count(*) from BackUpinfo union all
select "CustomQuery", count(*) from CustomQuery union all
select "DATA_SOURCE", count(*) from DATA_SOURCE union all
select "DBTableList", count(*) from DBTableList union all
select "DBTableType", count(*) from DBTableType union all
select "DEVICE", count(*) from DEVICE union all
......


3、结果:

......

xiaomeng 发表于 2008-3-19 11:28:15

赞!

mysql 4.1中无information_schema表。

mysql> use information_schema;
ERROR 1049 (42000): Unknown database 'information_schema'

还有其他办法吗?

kider 发表于 2008-3-19 16:42:53

目前没有

mysqlkumao 发表于 2008-4-10 09:01:36

:victory:

general007 发表于 2009-11-27 10:13:38

nice
页: [1]
查看完整版本: 计算数据库中所有表的记录数并输出.sql