Link to home
Start Free TrialLog in
Avatar of dastaub
dastaubFlag for United States of America

asked on

sql 2005 - Last Time Table Used in Query

Does SQL store the last date-time a table was part of a query?  

I'm trying to determine which tables are not being used and I would like to not bother asking about tables used on a daily basis, but ask about tables not used in months.
Avatar of Brendt Hess
Brendt Hess
Flag of United States of America image

Not directly.  However, some of this can be derived from the standard reports by database.  Use the Index Usage Statistics report as a good starting surrogate for this - if there is a table that hasn't had any index usage (assuming the table has an index), it likely has not been touched for the same time.  This value is only maintained since the last restart of the SQL Server, though.
ASKER CERTIFIED SOLUTION
Avatar of Bhavesh Shah
Bhavesh Shah
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of dastaub

ASKER

Below is code from supplied link.  It can get the data needed.
select
 t.name
 ,user_seeks
 ,user_scans
 ,user_lookups
 ,user_updates
 ,last_user_seek
 ,last_user_scan
 ,last_user_lookup
 ,last_user_update
 from
 sys.dm_db_index_usage_stats i JOIN
 sys.tables t ON (t.object_id = i.object_id)
 where
 database_id = db_id()