MySQL社区

标题: 计算数据库中所有表的记录数并输出.sql [打印本页]

作者: kider    时间: 2007-8-8 19:59
标题: 计算数据库中所有表的记录数并输出.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
赞!

mysql 4.1中无information_schema表。

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

还有其他办法吗?
作者: kider    时间: 2008-3-19 16:42
目前没有
作者: mysqlkumao    时间: 2008-4-10 09:01

作者: general007    时间: 2009-11-27 10:13
nice




欢迎光临 MySQL社区 (http://www.mysqlpub.com/) Powered by Discuz! X3.2