Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Declare @date datetime
- set @date = 1
- select DB_NAME(ius.database_id) as DBname
- ,o.name as ObjectName
- ,i.name as IndexName
- ,(ius.user_seeks + ius.system_seeks) as seeks
- ,(ius.user_scans + ius.system_scans) as scans
- ,(ius.user_lookups + ius.system_lookups) as lookups
- ,(ius.user_updates + ius.system_updates) as updates
- ,Case
- when COALESCE(ius.last_user_seek,@date) > COALESCE(ius.last_user_scan,@date) and COALESCE(ius.last_user_seek,@date) > COALESCE(ius.last_user_lookup,@date) and COALESCE(ius.last_user_seek,@date) > COALESCE(ius.last_user_update,@date) then last_user_seek
- when COALESCE(ius.last_user_scan,@date) > COALESCE(ius.last_user_seek,@date) and COALESCE(ius.last_user_scan,@date) > COALESCE(ius.last_user_lookup,@date) and COALESCE(ius.last_user_scan,@date) > COALESCE(ius.last_user_update,@date) then last_user_scan
- when COALESCE(ius.last_user_lookup,@date) > COALESCE(ius.last_user_scan,@date) and COALESCE(ius.last_user_lookup,@date) > COALESCE(ius.last_user_seek,@date) and COALESCE(ius.last_user_lookup,@date) > COALESCE(ius.last_user_update,@date) then last_user_seek
- when COALESCE(ius.last_user_update,@date) > COALESCE(ius.last_user_scan,@date) and COALESCE(ius.last_user_update,@date) > COALESCE(ius.last_user_seek,@date) and COALESCE(ius.last_user_update,@date) > COALESCE(ius.last_user_lookup,@date) then last_user_seek
- else null
- end as [lastUserAction]
- from sys.dm_db_index_usage_stats as ius
- INNER JOIN sys.indexes as i ON i.index_id = ius.index_id AND ius.[object_id] = i.[object_id]
- INNER JOIN sys.objects as o ON ius.[object_id] = o.[object_id]
- WHERE OBJECTPROPERTY(ius.OBJECT_ID,'IsUserTable') = 1
- and ius.database_id = (select db_id())
- order by DBname, ObjectName
- go
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement