Erzeugt eine Prozedur welche auflistet welche Indezies einer Datenbank am häufigsten ausgeführt wurden.

use master
go

if exists ( select * from sysobjects where type='P' and name = 'sp_indexstats' )
	drop procedure sp_indexstats
go	

create procedure sp_indexstats
as
select	OBJECT_NAME(object_id) AS Tabelle, si.name AS [Index], user_seeks, user_scans, user_lookups, user_updates
from sysindexes si join sys.dm_db_index_usage_stats iu on si.id = iu.object_id and si.indid = iu.index_id
where	database_id = DB_ID()
go

use AdventureWorks2008R2
go

exec sp_indexstats