Skip to main content

Posts

Showing posts with the label Last time database was used

Find Orphaned databases in SQL Server

Do you ever wonder if there are any databases in your environment that may just be there but not being used? I needed to make a comprehensive list of such databases i n order to clean up old databases and prep old/existing environment and migrate and consolidate them into a new sql server infrastructure. So I wrote this DMV query to obtain when a database was last accessed for a user query as well as those that were left OFFLINE but never removed. I executed this against CMS / Multi Server query an whola... within few seconds I had the complete list or rather a preliminary list for my intended purpose. Couple things to note first: 1. I only tested and ran this against SQL versions 2008 and up. 2. It uses a global temp table and removes when done Hope you find this use and please feel free to leave comments/feedback/suggestions for further improvement. SET nocount ON SET TRANSACTION isolation level READ uncommitted USE master go IF Object_id ( 'tempdb..##t_dba_db_last_ac...