>SQL Server: How to Read Trace File to Detect Database Detachment


On of our production server contains more then 200 databases. Few of them are rarely used but still required. Few days back, someone from DBA’s  team accidentally detached on of less used database. But once we need it we got error as there was no required database on server.
To find out, that when and who detached this database we have quickly executed a simple script.
First get current trace file name from sys.traces table
SELECT * FROM sys.traces
Then copy trace file name and assign it @trace_file parameter and execute following script.
DECLARE @trace_file NVARCHAR(500)
SELECT  @trace_file = ‘C:\Program Files\Microsoft SQL Server\MSSQL10.MSSQLSERVER\MSSQL\Log\log_88.trc’
FROM    [fn_trace_gettable](@trace_file, DEFAULT)
ORDER BY starttime DESC



Posted on April 26, 2011, in Sql Server Management, Traces and Logs. Bookmark the permalink. 1 Comment.

  1. So, does it mean that sys.traces table always logs the changes and we simply execute a select statement there? Or should we create a new trace file for future changes? Thanks.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: