Search

Monday, September 22, 2014

Query to find the Index with size

Use below query to find the Index with size in a table:

SELECT
OBJECT_Name(I.OBJECT_ID) AS TableName,
I.index_ID AS IndexID,
I.Name AS IndexName,
8 * SUM(A.Used_Pages)/1024 AS 'IndexSize in KB'
FROM sys.Indexes AS I
JOIN sys.Partitions AS p ON p.OBJECT_ID = I.OBJECT_ID AND p.index_ID = I.index_ID
JOIN sys.Allocation_Units AS A ON A.Container_ID = P.Partition_ID
WHERE I.Object_ID = Object_ID ('<Table_Name>')
GROUP BY I.OBJECT_ID,I.index_ID,I.Name

Replace <Table_Name> with Table Name

No comments:

Post a Comment