Home > Database > Mysql Tutorial > SQL 统计一个数据库中所有表记录的数量

SQL 统计一个数据库中所有表记录的数量

WBOY
Release: 2016-06-07 18:04:41
Original
1571 people have browsed it

最近公司的数据库发现有表的数据被弄掉了,有些数据表记录为0,于是想找出此数据库中到底有哪些数据表的记录都为0以缩小分析范围,可使用如下的SQL Statement

代码如下:
CREATE TABLE #tmptb(tbname sysname,tbrows int
,tbREserved varchar(10),tbData varchar(10)
,tbIndexSize varchar(10),tbUnUsed varchar(10))
INSERT INTO #tmptb exec sp_MSForEachTable 'EXEC sp_spaceused ''?'''
SELECT * from #tmptb --列出所有表的情况
SELECT tbrows ,tbname FROM #tmptb WHERE tbrows=0 --列出记录数据为0的表
ORDER BY tbname
DROP TABLE #tmptb

其中
tbname 表名
tbrows 记录数
tbREserved 保留空间
tbData 使用空间
tbIndexSize 索引使用空间
tbUnUsed 未用空间
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template