查看数据库表大小原创
6人赞赏了该文章
124次浏览
编辑于2024年02月28日 15:58:13
SELECT t.NAME AS 表名, s.Name AS 架构名, p.rows AS 行数, SUM(a.total_pages) * 8 / 1024.0 / 1024.0 AS 总空间GB, SUM(a.used_pages) * 8 / 1024.0 / 1024.0 AS 已使用空间GB, (SUM(a.total_pages) - SUM(a.used_pages)) * 8 / 1024.0 / 1024.0 AS 未使用空间GB 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 总空间GB DESC