SQLSERVER 查询所有表的数据量

 

--查询数据库中所有的表名及行数
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 A.NAME ,B.ROWS  FROM sysobjects  A JOIN sysindexes B ON A.id = B.id WHERE A.xtype = '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 

你可能感兴趣的:(db,sql,server)