How to find out the size of Indexes in SQL Server database?


we can find or calculate the size of every indexes in a table through sys.indexes and sys.dm_db_partition_stats DMF.



SELECT SCHEMA_NAME(tn.schema_id) [Schema_Name],
tn.[name] AS [Table_name],ixn.[name] AS [Index_name],
SUM(p.[used_page_count]) * 8/1024.0 AS [Index_size_in_MB]
FROM sys.dm_db_partition_stats AS p
INNER JOIN sys.indexes AS ixn ON p.[object_id] = ixn.[object_id]
AND p.[index_id] = ixn.[index_id]
INNER JOIN sys.tables tn ON tn.OBJECT_ID = ixn.object_id
GROUP BY tn.[name], ixn.[name], tn.schema_id
ORDER BY tn.[name]

Output:-


 

Leave a Reply

Your email address will not be published. Required fields are marked *