一次计算所有表的行数 [英] Counting rows for all tables at once

查看:27
本文介绍了一次计算所有表的行数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的是 SQL Server 2005,想知道如何获取所有表的列表,每个表的记录数.

I'm using SQL Server 2005 and would like to know how I can get a list of all tables with the number of records in each.

我知道我可以使用 sys.tables 视图获取表列表,但我无法找到计数.

I know I can get a list of tables using the sys.tables view, but I'm unable to find the count.

谢谢

推荐答案

来自这里:http://web.archive.org/web/20080701045806/http://sqlserver2000.databases.aspfaq.com:80/how-do-i-get-a-list-of-sql-server-tables-and-their-row-counts.html

SELECT 
    [TableName] = so.name, 
    [RowCount] = MAX(si.rows) 
FROM 
    sysobjects so, 
    sysindexes si 
WHERE 
    so.xtype = 'U' 
    AND 
    si.id = OBJECT_ID(so.name) 
GROUP BY 
    so.name 
ORDER BY 
    2 DESC

这篇关于一次计算所有表的行数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆