5

I can use sp_spaceused tablename to get the total index size for that table. But is there a way to get all indexes of that table's size individually?

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
MSSQL
  • 61
  • 1
  • 2
  • 1
    Possible duplicate of [Table and Index size in SQL Server](http://stackoverflow.com/questions/316831/table-and-index-size-in-sql-server) – Gerardo Lima Feb 10 '17 at 09:48

1 Answers1

6

table-and-index-size-in-sql-server

Following script is copied from the above answer from Rob Garisson

SELECT
    i.name                  AS IndexName,
    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('dbo.TableName')
ORDER BY i.name

SELECT
    i.name              AS IndexName,
    SUM(page_count * 8) AS IndexSizeKB
FROM sys.dm_db_index_physical_stats(
    db_id(), object_id('dbo.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
Community
  • 1
  • 1
Kashif
  • 14,071
  • 18
  • 66
  • 98