SQL查看数据库中每张表的数据量和总数据量

时间:2023-03-08 17:35:10
SQL查看数据库中每张表的数据量和总数据量

查看所有表对应的数据量

SELECT   a.name AS 表名, MAX(b.rows) AS 记录条数
FROM sys.sysobjects AS a INNER JOIN
sys.sysindexes AS b ON a.id = b.id
WHERE (a.xtype = 'u')
GROUP BY a.name
ORDER BY 记录条数 DESC

查看数据库的总数据量

SELECT   SUM(记录条数) AS 总记录数
FROM (SELECT TOP (10000) a.name AS 表名, MAX(b.rows) AS 记录条数
FROM sys.sysobjects AS a INNER JOIN
sys.sysindexes AS b ON a.id = b.id
WHERE (a.xtype = 'u')
GROUP BY a.name
ORDER BY 记录条数 DESC) AS t1