温馨提示×

sqlserver怎么查看所有表大小

小亿
948
2024-03-07 09:59:56
栏目: 云计算

要查看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为单位)的结果集。

0