can we get an output for list of databases which were not modified for last two months in a server and based on that we have to delete all of them.
I have tried below is the query: --identify when a user database was last accessed--
SELECT DatabaseName ,MAX(LastAccessDate) DatabaseLastAccessedOn FROM ( SELECT DB_NAME(database_id) DatabaseName ,last_user_seek ,last_user_scan ,last_user_lookup ,last_user_update FROM sys.dm_db_index_usage_stats ) AS Pvt UNPIVOT ( LastAccessDate FOR last_user_access IN ( last_user_seek ,last_user_scan ,last_user_lookup ,last_user_update ) ) AS Unpvt GROUP BY DatabaseName HAVING DatabaseName NOT IN ('master' ,'tempdb' ,'model' ,'msdb') ORDER BY 2
Need a query to find DBs which were not accessed/modified for the last 2 months and delete them. i have SQL express edition.