Find overlapping indexes with ease in SQL Server 2005
In [sys].[dm_db_index_usage_stats] could be used to find unused indexes. The SQL Server Programmability & API Development Blog recently posted a
“Simple script, eh?” Well, in this case we’re talking about a three-part process:
- Create a user-defined function and a view
- Run a SELECT statement to expose the overlapping indexes
- Clean up the view and the function
If you’re worried about running such a thing in a production environment, you can either:
- Run the script during off-peak hours
- Alter the script to set the isolation level to READ UNCOMMITTED and include the NOLOCK hint on the objects referenced (if your environment is stable there’s no reason to fear the dirty/phantom read issues inherent in this approach)
- Create the function and view, then create another database from a snapshot, and then run the SELECT on the snapshot database
The blog outlines some common concerns when dropping existing indexes and reviews a few index usage basics to qualify the results of the query. This can be a very quick, time-saving process and a good way to jump start your own database maintenance initiatives.