Determine Index size of a particular table in SQL Server

You can use below T-SQL query to determine size of Index

Either method, will help you to determine Size of Indexes of a particular Table

Note: Please replace SchemaName.TableName in below query with the appropriate schema and table name whose index size you want to find

/* Method 1 */
SELECT    
       i.name                  AS IndexName,    
       SUM(s.used_page_count) * 8   AS IndexSizeKB
FROM sys.dm_db_partition_stats  AS s 
JOIN sys.indexes                AS i
ON s.[object_id] = i.[object_id] AND s.index_id = i.index_id
WHERE s.[object_id] = object_id('SchemaName.TableName')
GROUP BY i.name
ORDER BY i.name



/* Method 2 */
SELECT    
       i.name              AS IndexName,    
       SUM(page_count * 8) AS IndexSizeKB
FROM sys.dm_db_index_physical_stats(    
       db_id(), object_id('SchemaName.TableName'), NULL, NULL, 'DETAILED') AS s
JOIN sys.indexes AS i
ON s.[object_id] = i.[object_id] AND s.index_id = i.index_id
GROUP BY i.name
ORDER BY i.name




Comments

Popular posts from this blog

Calculating Age of the person in T-SQL

How to Troubleshoot Subscription issue in Reporting Services

MDX Queries - Current Day - Month and Year