Skip to content

Instantly share code, notes, and snippets.

@richardbasile
Last active March 6, 2018 15:29
Show Gist options
  • Save richardbasile/b3aaf285b507fda8a4383f641f71d323 to your computer and use it in GitHub Desktop.
Save richardbasile/b3aaf285b507fda8a4383f641f71d323 to your computer and use it in GitHub Desktop.
SQL Server - Indexes
SELECT t.name AS [TableName]
, i.name AS [IndexName]
, i.is_primary_key
, i.is_unique_constraint
, i.type_desc
, SUM(s.[used_page_count]) * 8 AS IndexSizeKB
FROM sys.indexes i
JOIN sys.tables t ON t.object_id = i.object_id
JOIN sys.dm_db_partition_stats s ON s.object_id = i.object_id AND s.index_id = i.index_id
GROUP BY t.name
, i.name
, i.is_primary_key
, i.is_unique_constraint
, i.type_desc
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment