SqlServer查询表空间占用情况
2022-07-03 本文已影响0人
洛奇lodge
查询sql语句
SELECT
obj.name "表名",
pt.rows "行数",
SUM(acu.used_pages)*8/1024 "大小(MB)"
FROM sys.objects obj
JOIN sys.indexes idx on obj.object_id = idx.object_id
JOIN sys.partitions pt on obj.object_id = pt.object_id
JOIN sys.allocation_units acu on acu.container_id = pt.partition_id
WHERE obj.type = 'U' AND idx.index_id IN (0, 1)
GROUP BY obj.name, pt.rows
ORDER BY 3 DESC