Thursday 23 July 2009

SQL List indexes in db with fragmentation > 30 %


   1:  SELECT 
   2:      OBJECT_NAME(object_id) ObjectName,
   3:      index_id,
   4:      index_type_desc,
   5:      avg_fragmentation_in_percent
   6:  FROM sys.dm_db_index_physical_stats
   7:      (DB_ID('AdventureWorks'),NULL, NULL, NULL, 'LIMITED')
   8:  WHERE 
   9:      avg_fragmentation_in_percent > 30
  10:  ORDER BY 
  11:      OBJECT_NAME(object_id)

No comments: