Created
October 27, 2019 11:34
-
-
Save james-s-tayler/ef4c54b7b8ae12f395624400b5e4eade to your computer and use it in GitHub Desktop.
SQL Server Index Fragmentation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
select | |
ps.object_id, | |
idx.name, | |
idx.type_desc, | |
ps.alloc_unit_type_desc, | |
ps.avg_fragmentation_in_percent, | |
ps.fragment_count, | |
ps.avg_fragment_size_in_pages, | |
ps.page_count | |
from | |
sys.dm_db_index_physical_stats(db_id(), NULL, NULL, NULL, NULL) ps | |
join | |
sys.indexes idx | |
on idx.object_id = ps.object_id | |
and idx.index_id = ps.index_id | |
order by | |
avg_fragmentation_in_percent desc, | |
page_count desc; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment