Wednesday, 8 January 2014

Find last time a table has been accessed

The following SQL script will give you information about the last time a table has been accessed, or updated:
select
      so.name,
      last_user_seek = max(last_user_seek),
      last_user_scan = max(last_user_scan),
      last_user_lookup = max(last_user_lookup),
      last_user_update = max(last_user_update)
from
      sys.dm_db_index_usage_stats s
inner join sysobjects so
      on s.object_id = so.id
where
      [database_id] = db_id()
group by
      so.name

No comments:

Post a Comment

Updating massive amount of rows whilst avoiding blocking

The following SQL is a good means to split an update on a massive table into smaller chunks, whilst reducing blocking. The method is to upda...