sqlserver数据库表大小查询语句
时间: 2023-06-16 18:08:27 浏览: 192
查询Sql Server数据库数据表大小
4星 · 用户满意度95%
你可以使用以下SQL语句来查询SQL Server数据库中每个表的大小信息:
```
SELECT
t.NAME AS TableName,
p.rows AS RowCounts,
SUM(a.total_pages) * 8 AS TotalSpaceKB,
SUM(a.used_pages) * 8 AS UsedSpaceKB,
(SUM(a.total_pages) - SUM(a.used_pages)) * 8 AS UnusedSpaceKB
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
i.OBJECT_ID > 255 AND
i.index_id <= 1
GROUP BY
t.NAME, p.Rows
ORDER BY
TotalSpaceKB DESC
```
这将为您提供每个表的总空间,已用空间和未使用空间的大小。
阅读全文