Search This Blog

Sunday, 20 May 2012

How to show when a SQL Server Database was last accessed

If you have SQL Server databases and you are unsure if they are still in use then you can use this query to show you the last access time since the server was rebooted.

select, a.dbid, max(last_user_seek), max(last_user_scan)
from sys.sysdatabases a
left outer join sys.dm_db_index_usage_stats b on a.dbid = b.database_id
group by, a.dbid

No comments:

Post a Comment