Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2008 Forums
 SQL Server Administration (2008)
 Does Detached DB leave a trace?

Author  Topic 

dbthj
Posting Yak Master

143 Posts

Posted - 2011-04-26 : 11:18:00
When you detach a database, it disappears from sysdatabases. BOL says in one place, "removes it from the instance of SQL Server". In another place it says, "The database is marked as deleted". I'm wondering if it is truly gone or if it is "marked" as gone. My question is: Besides the underlying data and log files, is there any trace at all within the SQL Server instance of that database?
If so, do you know where this record is reatained and what is remembers about it?

robvolk
Most Valuable Yak

15732 Posts

Posted - 2011-04-26 : 11:30:29
You can look in the backup history (backupset table) in msdb and check the database name, any names not current on the server have been dropped or detached. If you dig into the backupfile table you can look for files that still exist on the server and would indicate a detached database.
Go to Top of Page

lionofdezert
Aged Yak Warrior

885 Posts

Posted - 2011-04-26 : 11:36:36
--First Get trace file name
SELECT * FROM sys.traces
GO
--Replace trace file name and execute follow batch
DECLARE @trace_file NVARCHAR(500)
SELECT @trace_file = 'C:\Program Files\Microsoft SQL Server\MSSQL10.MSSQLSERVER\MSSQL\Log\log_88.trc'

SELECT *
FROM [fn_trace_gettable](@trace_file, DEFAULT)
WHERE TextData LIKE '%DETACH%'
ORDER BY starttime DESC

--------------------------
http://connectsql.blogspot.com/
Go to Top of Page
   

- Advertisement -