要查看SQL Server中所有表的大小,可以使用以下查詢語句:
SELECT
t.NAME AS TableName,
s.NAME AS SchemaName,
p.rows AS RowCounts,
SUM(a.total_pages) * 8 AS TotalSizeKB
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
LEFT OUTER JOIN
sys.schemas s ON t.schema_id = s.schema_id
GROUP BY
t.Name, s.Name, p.Rows
ORDER BY
TotalSizeKB DESC;
這將返回一個包含所有表的名稱、模式、行數和大小(以KB為單位)的結果集。