Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2012 Forums
 Transact-SQL (2012)
 find out what query is using an index

Author  Topic 

Kimi86
Yak Posting Veteran

79 Posts

Posted - 2013-02-07 : 07:20:04
I am trying to find out what query is using a particular index in my database.
When I look at sys.dm_db_index_usage_stats the count for User_seeks keeps going up but I dunno any place where it must be being used. I basically want to delete it as a work around since i have some space issues in my database and adding space will take some time. I know that the index is being used somewhere looking at sys.dm_db_index_usage_stats but i am quite puzzled what program or query is using it.. Any idea what I can do

srimami
Posting Yak Master

160 Posts

Posted - 2013-02-08 : 17:21:14
Use the following query and see if User_seeks or user_Scans are being used. If user_seeks & user_scans are Zero, you can drop the indexes.

SELECT OBJECT_NAME(S.[OBJECT_ID]) AS [OBJECT NAME],
I.[NAME] AS [INDEX NAME],
USER_SEEKS,
USER_SCANS,
USER_LOOKUPS,
USER_UPDATES
FROM SYS.DM_DB_INDEX_USAGE_STATS AS S
INNER JOIN SYS.INDEXES AS I
ON I.[OBJECT_ID] = S.[OBJECT_ID]
AND I.INDEX_ID = S.INDEX_ID
WHERE OBJECTPROPERTY(S.[OBJECT_ID],'IsUserTable') = 1

Go to Top of Page
   

- Advertisement -