Check usage of indexes

Last updated:

Warning: Review and test in a non-production environment before running.

Back to results

SELECT ops.database_id, ops.index_id, 
    DB_NAME(ops.database_id) AS database_name, OBJECT_NAME(ops.object_id, database_id) AS tableview_name, idx.[name] as index_name,
    ops.range_scan_count, ops.singleton_lookup_count, ops.row_lock_count, ops.page_lock_count
FROM sys.dm_db_index_operational_stats(DB_ID(), NULL, NULL, NULL) AS ops
RIGHT JOIN sys.indexes AS idx ON ops.object_id = idx.object_id and ops.index_id = idx.index_id
WHERE ops.database_id = DB_ID() AND ops.object_id > 100
ORDER BY ops.range_scan_count ASC, ops.row_lock_count DESC, ops.page_lock_count DESC
GO