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

 

posted @ 2017-12-28 17:32  上古时期的码农  阅读(19019)  评论(0编辑  收藏  举报