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

时间:2021-04-04 13:57:27

查看所有表对应的数据量

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