Created
January 27, 2015 16:43
-
-
Save veysby/fdeac9145d11f82a093d to your computer and use it in GitHub Desktop.
MSSQL: 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 | |
OBJECT_NAME(ind.OBJECT_ID) AS TableName, | |
ind.name AS IndexName, | |
indexstats.index_type_desc AS IndexType, | |
indexstats.avg_fragmentation_in_percent | |
FROM sys.dm_db_index_physical_stats(DB_ID(), NULL, NULL, NULL, NULL) indexstats | |
INNER JOIN sys.indexes ind ON ind.object_id = indexstats.object_id AND ind.index_id = indexstats.index_id | |
WHERE indexstats.avg_fragmentation_in_percent > 30--You can specify the percent as you want | |
ORDER BY | |
indexstats.avg_fragmentation_in_percent DESC |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment