sqlserver怎么查看所有表大小

1451
2024/3/5 9:59:56
栏目: 云计算
开发者测试专用服务器限时活动,0元免费领,库存有限,领完即止! 点击查看>>

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

辰迅云「云服务器」,即开即用、新一代英特尔至强铂金CPU、三副本存储NVMe SSD云盘,价格低至29元/月。点击查看>>

推荐阅读: sqlserver中dateadd函数的用法是什么