Wednesday, October 12, 2016

Find SQL Server Databases that are not accessed after last reboot

I have written a post tilted When was my SQL Server Database last accessed? that talks about how to find the last accessed date and time of databases. As per one of the comments, it is important to find out databases that were not accessed after last reboot as well, hence wrote this query for that.

It may be helpful to you.

  1. SELECT name DatabaseName  
  2. FROM sys.databases  
  3. WHERE name NOT IN ('master''tempdb''model''msdb'-- and if you other system DBs  
  4. EXCEPT  
  5. SELECT DISTINCT  
  6.  DB_NAME(database_id) DatabaseName  
  7. FROM sys.dm_db_index_usage_stats  
  8. ORDER BY 1  


No comments: