Sql-server – How to find the last time a database was accessed

sql-serversql-server-2005

In SQL Server 2005, can you easily determine the last time someone queried a database.

Best Solution

SELECT
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
WHERE
[database_id] = DB_ID()

One caveat with this method is that the information in the DMV will be cleared and nulled whenever you restart SQL Server.