Created
March 14, 2019 09:59
-
-
Save kshimi/de54e78cc70114856dad095ded085588 to your computer and use it in GitHub Desktop.
SQLServer check 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
-- Find the average fragmentation percentage of all indexes | |
-- in the HumanResources.Employee table. | |
SELECT | |
i.index_id, name | |
, s.avg_fragmentation_in_percent | |
, s.avg_fragment_size_in_pages | |
, s.fragment_count, s.page_count | |
FROM sys.dm_db_index_physical_stats (NULL, NULL, NULL, NULL, NULL) AS s | |
JOIN sys.indexes AS i ON a.object_id = b.object_id AND a.index_id = b.index_id | |
where s.avg_fragmentation_in_percent > 30 | |
order by s.avg_fragmentation_in_percent desc | |
; | |
GO |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment