Sunday, March 9, 2014

Check SQL Server a specified database index fragmentation percentage (avg_fragmentation_in_percent)

SELECT OBJECT_NAME(ind.OBJECT_IDAS TableNameind.name AS IndexNameindexstats.index_type_desc AS IndexTypeindexstats.avg_fragmentation_in_percent  FROM sys.dm_db_index_physical_stats(DB_ID(), NULLNULLNULLNULLindexstats  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  ORDER BY indexstats.avg_fragmentation_in_percent DESC

No comments:

Post a Comment