我有一个索引 - 让我们称之为IX_MY_INDEX
- 在SQL Server表中(兼容模式80和90)我想确定它的大小。我该怎么做?
更新: Allain Lalonde的第二个解决方案仅在兼容模式设置为90时才有效。但是,我正在处理的特定数据库是兼容模式80.有没有人有兼容模式80的解决方案?
答案 0 :(得分:9)
您可以确定表格上的所有索引的大小(以及其他内容),如下所示:
EXEC sp_spaceused TableName;
如需完整分类,您可以:
SELECT *
FROM sys.dm_db_index_physical_stats(db_id(), object_id('TableName'), null, null, 'DETAILED');
答案 1 :(得分:0)
根据How to Find Size of All the Indexes on the Database上的帖子改编而成,您可以使用:
SELECT OBJECT_SCHEMA_NAME(i.OBJECT_ID) AS SchemaName,
OBJECT_NAME(i.OBJECT_ID) AS TableName,
i.[name] AS IndexName,
i.index_id AS IndexID,
8 * SUM(a.used_pages) AS [Indexsize(KB)]
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 a ON a.container_id = p.partition_id
GROUP BY i.OBJECT_ID, i.index_id, i.[name]
ORDER BY OBJECT_NAME(i.OBJECT_ID), i.index_id
使用以下表格: