I like this query too (though it will run a while on a large db) as it shows indexes usage stats too.Occassionally I'll target indexes to drop based on the resultdeclare @db intset @db = db_id()SELECT object_name(s.object_id) tbl, i.name idx, p.rows, s.index_type_desc, index_depth, avg_fragmentation_in_percent, s.fragment_count, s.page_count, user_seeks, user_scans, user_lookups, user_updates, last_user_seek, last_user_scan, last_user_lookup, last_user_updateFROM sys.dm_db_index_physical_stats (@db, null, NULL, NULL, NULL) sjoin sys.indexes ion i.object_id = s.object_idAnd i.index_id = s.index_idJOIN sys.partitions pOn p.object_id = s.object_idAnd p.partition_number = s.partition_numberAnd p.index_id = s.index_idLEFT JOIN Sys.dm_db_index_usage_stats usOn us.object_id = s.object_idAnd us.index_id = s.index_idWHERE avg_fragmentation_in_percent > 20--And page_count > 99And s.database_id = @dbAnd s.index_type_desc <> 'HEAP'Order By avg_fragmentation_in_percent desc;GO
I have the page_count filter commented out here...again, I want to see not only fragmented indexes, but usage stats. If I find an index with a low number of pages (or rows) it is likely that it isn't used at all and I want to know that.