SQLServer 统计数据表记录数空间占用 [数据库 SQLServer]
CREATE TABLE _tmp
    (
      NAME VARCHAR(50) ,
      ROWS INT ,
      reserved VARCHAR(50) ,
      DATA VARCHAR(50) ,
      index_size VARCHAR(50) ,
      unused VARCHAR(50)
    );
INSERT  INTO _tmp
        ( NAME ,
          ROWS ,
          reserved ,
          DATA ,
          index_size ,
          unused
        )
        EXEC sp_MSforeachtable @command1 = "sp_spaceused '?'";
SELECT  NAME AS '表名' ,
        [ROWS] AS '记录数' ,
        reserved AS '占用空间' ,
        DATA AS '数据大小' ,
        index_size AS '索引大小' ,
        unused AS '未使用空间'
FROM    _tmp
WHERE   NAME <> '_tmp'
ORDER BY ROWS DESC
       
DROP TABLE _tmp