查看SQL Server数据库各表数据量与占用空间

SELECT          SCHEMA_NAME(t.schema_id)                [Owner],
                t.name                                  AS TableName,
                p.rows                                  AS RowCounts,
                SUM(a.total_pages) * 8 / 1024 / 1024.00 AS TotalSpaceGB,
                SUM(a.total_pages) * 8 / 1024.00        AS TotalSpaceMB
FROM            sys.tables           t
    INNER JOIN  sys.indexes          i
        ON t.object_id = i.object_id
    INNER JOIN  sys.partitions       p
        ON i.object_id = p.object_id
           AND  i.index_id = p.index_id
    INNER JOIN  sys.allocation_units a
        ON p.partition_id = a.container_id
WHERE           t.name NOT LIKE 'dt%'
                AND t.is_ms_shipped = 0
                AND i.object_id > 255
GROUP BY        SCHEMA_NAME(t.schema_id),
                t.name,
                p.rows
ORDER BY        TotalSpaceGB DESC;

  

posted on 2024-11-28 13:17  itjeff  阅读(16)  评论(0编辑  收藏  举报

导航