SQL Script: – How to find the last access date of a database

DBA

SQL Script to find database last access date

Sometime we create databases on Test/ Development database servers for temporary uses for short duration and  forgot to delete them after the work got completed. As a part of house keeping activity, we need to find out when a database is last accessed in order to find out the databases which are not used since long time and can be a deleted.
Below mentioned SQL query will going to help you in finding out the last access date of all the databases of a SQL server
SELECT name as [Database Name], [Last Access Date] =(select MAX(temp.lastaccess)
from ( select lastaccess =
max(last_user_seek)
where max(last_user_seek)is not null
union all
select lastaccess = max(last_user_scan)
where max(last_user_scan)is not null
union all
select lastaccess = max(last_user_lookup)
where max(last_user_lookup) is not null
union all
select lastaccess =max(last_user_update)
where max(last_user_update) is not null) temp)
FROM master.dbo.sysdatabases sysdb
left outer join sys.dm_db_index_usage_stats Idxus
on sysdb.dbid= Idxus.database_id
group by sysdb.name

37 thoughts on “SQL Script: – How to find the last access date of a database

  1. Pingback: Extra resources
  2. Pingback: didi referral code
  3. Pingback: 카지노사이트
  4. Pingback: movies
  5. Pingback: movies online
  6. Pingback: karan johar
  7. Pingback: Top Movies
  8. Pingback: Movies1
  9. Pingback: 11 10 2019
  10. Pingback: Serial smotret
  11. Pingback: kinokrad
  12. Pingback: kinokrad 2020
  13. Pingback: nha cai fun88
  14. Pingback: casino
  15. Pingback: filmy-kinokrad
  16. Pingback: kinokrad-2019
  17. Pingback: serial
  18. Pingback: cerialest.ru
  19. Pingback: dorama hdrezka
  20. Pingback: HDrezka
  21. Pingback: kinosmotretonline
  22. Pingback: LostFilm HD 720

Leave a Reply