SQLSERVER 查询所有表的数据量

2020年3月19日 0 条评论 74 次阅读 1 人点赞
--查询数据库中所有的表名及行数
SELECT  a.name ,  b.rows  FROM    sysobjects AS a
INNER JOIN sysindexes AS b ON a.id = b.id
WHERE   ( a.type = 'u' )  AND ( b.indid IN ( 0, 1 ) )
ORDER BY b.rows DESC

--查询所有的表名及空间占用量情况
SELECT  OBJECT_NAME(id) tablename ,
        8 * reserved / 1024 reserved ,
        RTRIM(8 * dpages) AS 'used(kb)' ,
        8 * ( reserved - dpages ) / 1024 unused ,
        8 * dpages / 1024 - rows / 1024 * minlen / 1024 free
FROM    sysindexes
WHERE   indid = 1
ORDER BY reserved DESC 

Mr.Seaning

一个中年油腻大叔