--------------------------------------------------------------------------------
--  File        :   Demo 05_Enable the trace flags for recording deadlock information in the error log,2005+.sql
--
--  Purpose     :   This script configures SQL Server to write the deadlock 
--                  information to the SQL Server error log each time that a 
--                  deadlock occurs.
--
--                  See "Detecting and Ending Deadlocks" <http://msdn.microsoft.com/en-us/library/ms178104.aspx>
--                  for more information.
--
--                  NOTE: To undo the change, run the following T-SQL:
--
--                      DBCC TRACEOFF
--                      (
--                          3605,
--                          1222,
--                          -1
--                      );
--
--                  NOTE: This setting will be lost when the instance is 
--                  restarted.  Trace flags can also be configured as startup 
--                  options.  See "Using the SQL Server Service Startup Options" <http://msdn.microsoft.com/en-us/library/ms190737.aspx>
--                  for more information.
--
--  SQL Server  :   SQL Server 2005 (9.0)
--                  SQL Server 2008 (10.0)
--                  SQL Server 2008 R2 (10.5)
--
--  Version     :   3.0006.0090.0019 (2010-05-31)
--------------------------------------------------------------------------------

USE [tempdb];

GO

DBCC TRACEON
(
    3605,   --  Dump the output of trace flag 1222 in the error log
    1222,   --  Provide deadlock graphs (without the XML tags)
    -1      --  Apply to all sessions/connections
);

--  To turn off the trace flag, select and run the following code.
/*
DBCC TRACEOFF
(
    3605,
    1222,
    -1
);
*/

GO
