Orphaned Datafiles ?

Occasionally, in my hunt for space I find a datafile with a name unrelated to any current installed database. This query lists datafiles and the database’s they belong to …

SELECT DB_NAME(database_id) DBName,
	   [name] Logical_Name,
       Physical_Name, 
       CONVERT(FLOAT, size) * 8 / 1000000 SizeGB
FROM master.sys.master_files
-- WHERE DB_NAME(database_id) like 'Man%'
WHERE physical_name LIKE 'c%' -- on the c-drive!
-- ORDER BY database_id
ORDER BY size DESC;

Leave a comment