Skip to content

Instantly share code, notes, and snippets.

@josephhanson
Created June 3, 2017 11:18
Show Gist options
  • Save josephhanson/549bbf89f27c3320c1ac13955e1dc7e3 to your computer and use it in GitHub Desktop.
Save josephhanson/549bbf89f27c3320c1ac13955e1dc7e3 to your computer and use it in GitHub Desktop.
SQL - Page Fragmentation
SELECT a.index_id, name, avg_fragmentation_in_percent, fragment_count,
avg_fragment_size_in_pages
FROM sys.dm_db_index_physical_stats(DB_ID('database'),
OBJECT_ID('table'), NULL, NULL, NULL) AS a
JOIN sys.indexes AS b ON a.OBJECT_ID = b.OBJECT_ID AND a.index_id = b.index_id;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment