sql-server – 如何知道哪些表占用了SQL Server 2005数据库中最多的空间?

如何知道哪些表占用了SQL Server 2005数据库中的最大空间?

我确信有一些系统存储过程显示此信息。

我有一个TEST数据库从1Tb增长到23TB。我们目前在数据库中做了很多客户端转换测试,这需要多次运行相同的转换存储过程。它做DELETE,我确信是增加事务日志。但这让我想到问这个问题。

提前致谢。

尝试此脚本 – 它将列出数据库中所有表的数据行(以及所使用的总空间)使用的行数和空间:

SELECT 
 t.NAME AS TableName,
 i.name AS indexName,
 SUM(p.rows) AS RowCounts,
 SUM(a.total_pages) AS TotalPages, 
 SUM(a.used_pages) AS UsedPages, 
 SUM(a.data_pages) AS DataPages,
 (SUM(a.total_pages) * 8) / 1024 AS TotalSpaceMB, 
 (SUM(a.used_pages) * 8) / 1024 AS UsedSpaceMB, 
 (SUM(a.data_pages) * 8) / 1024 AS DataSpaceMB
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, i.object_id, i.index_id, i.name 
ORDER BY 
 OBJECT_NAME(i.object_id) 
翻译自:https://stackoverflow.com/questions/3927231/how-can-you-tell-what-tables-are-taking-up-the-most-space-in-a-sql-server-2005-d

转载注明原文:sql-server – 如何知道哪些表占用了SQL Server 2005数据库中最多的空间?