Agent Jobs

Find When A Database Was Last Accessed

Here’s some very basic sql logic that shows when a database was last accessed.

use master;
set nocount on

select
last_user_seek = max(convert(char, last_user_seek, 9))
,	last_user_scan = max(convert(char, last_user_scan, 9))
,	last_user_lookup = max(convert(char, last_user_lookup, 9)) ,	last_user_update = max(convert(char, last_user_update, 9)) from
sys.dm_db_index_usage_stats
where
        db_name(database_id) = 'mydb'
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s