SQL: Index Fragmentation status

SELECT S.name as 'Schema',
T.name as 'Table',
I.name as 'Index',
FROM sys.dm_db_index_physical_stats (DB_ID(), NULL, NULL, NULL, NULL) AS DDIPS
INNER JOIN sys.tables T on T.object_id = DDIPS.object_id
INNER JOIN sys.schemas S on T.schema_id = S.schema_id
INNER JOIN sys.indexes I ON I.object_id = DDIPS.object_id
AND DDIPS.index_id = I.index_id
WHERE DDIPS.database_id = DB_ID()
and I.name is not null
AND DDIPS.avg_fragmentation_in_percent > 0
ORDER BY DDIPS.avg_fragmentation_in_percent desc

One Comment on “SQL: Index Fragmentation status

  1. Use sys.dm_db_index_physical_stats to determine fragmentation for the indexes. The column avg_fragmentation_in_percent shows you the fragmentation in percent. Set the fill factor for a server A server-wide fill factor level of 80 is optimal to support growth and minimize fragmentation for SharePoint.

Leave a Reply

Your email address will not be published. Required fields are marked *