Database last accessed

How Can We Help?

You are here:
< Back
 -- Get Last Restart time

SELECT
crdate
FROM
sysdatabases
WHERE name = 'tempdb'

go

-- get last db access time (Null = no access since last reboot)

SELECT name, last_access =(select X1= max(LA.xx)
from ( select xx =
max(last_user_seek)
where max(last_user_seek)is not null
union all
select xx = max(last_user_scan)
where max(last_user_scan)is not null
union all
select xx = max(last_user_lookup)
where max(last_user_lookup) is not null
union all
select xx =max(last_user_update)
where max(last_user_update) is not null) LA)
FROM master.dbo.sysdatabases sd
left outer join sys.dm_db_index_usage_stats s
on sd.dbid= s.database_id
group by sd.name

If you don’t have trace setup, then this will give you the last time a database was accessed.

This is intended to see if the database has been in use lately, nothing else.