Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you find the last time a database was accessed?

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

like image 338
way0utwest Avatar asked Apr 02 '09 20:04

way0utwest


People also ask

How can I tell when a SQL database was last used?

SQL Server can log event information for logon attempts and you can view it by reviewing the errorlog. By turning on the auditing level of SQL Server.

How can I tell if a database is being used?

Another way to see if your database is in use is to look and see if the indexes are being used. Information on index usage is held in the sys. dm_db_index_usage_stats table since the last server reboot, and can be queried using this statement which can be tailored to select the data you need.

How can you tell when a database was last updated?

If a user wants to find out when was the last table updated he can query dynamic management view (DMV) – sys. dm_db_index_usage_stats and easily figure out when was the table updated last.


1 Answers

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.

like image 171
James Allen Avatar answered Oct 04 '22 10:10

James Allen