Thursday, December 20, 2012

sql server when was the database table accessed last time


-- this works starting 2008 onwards
with cte as
(
select
(select min(last_user_dt) from (values (last_user_update),(last_user_seek),(last_user_scan),(last_user_lookup)) as all_val(last_user_dt)) as dt
,DB_NAME(database_id) as dbName
from sys.dm_db_index_usage_stats
)
select min(dt) as since from cte where
dbName = 'NORTHWIND'



-- to check when was the database accessed last time. use the below.
source : https://www.mssqltips.com/sqlservertip/3171/identify-sql-server-databases-that-are-no-longer-in-use/


No comments:

Post a Comment

Featured Post

SQL Server AWS Migration BCP

stored procedure to generate BCP scritps to migrate the SQL Server database. Developed this stored procedure on my labs to simulate t...

Contributors