如何在sql server 2005中找到特定索引的磁盘大小?
答案 0 :(得分:9)
USE master
SELECT SUM(used_page_count) * 8 AS [Size in kb]
FROM sys.indexes i
JOIN sys.dm_db_partition_stats p ON p.object_id = i.object_id AND i.index_id = p.index_id
WHERE i.object_id=OBJECT_ID('dbo.spt_values') AND i.name='ix2_spt_values_nu_nc'
答案 1 :(得分:2)
Find out the disk size of an index:
SELECT
OBJECT_NAME(I.OBJECT_ID) AS TableName,
I.name AS IndexName,
8 * SUM(AU.used_pages) AS 'Index size (KB)',
CAST(8 * SUM(AU.used_pages) / 1024.0 AS DECIMAL(18,2)) AS 'Index size (MB)'
FROM
sys.indexes I
JOIN sys.partitions P ON P.OBJECT_ID = I.OBJECT_ID AND P.index_id = I.index_id
JOIN sys.allocation_units AU ON AU.container_id = P.partition_id
WHERE
OBJECT_NAME(I.OBJECT_ID) = '<TableName>'
GROUP BY
I.OBJECT_ID,
I.name
ORDER BY
TableName
答案 2 :(得分:0)
您可以使用存储过程&#34; sp_spaceused&#34;。它会告诉你索引使用了多少空间以及用于数据的空间。
USE AdventureWorks2012;
GO
EXEC sp_spaceused 'Purchasing.Vendor';
GO