Trace Flags are a Handy options to debug behaviors of SQL Server components and to gather information regarding the same. Lets get straight to the Flags.
Q. How to Turn a Trace Flag ON
A. DBCC TRACEON (TRACEFLAG)
Q. How to Turn a Trace Flag OFF
A. DBCC TRACEOFF (TRACEFLAG)
Q. I cannot see the output of a Trace Flag on my Client or Query window(s).
A. DBCC TRACEON (3604,-1) will output the result of the TRACEFLAG the Client Window.
Q. What is the –1?
A. –1 will turn the TRACEFLAG on for all the clients and not Just the your session/client. It is set at server level. so even if you exit your session/client, it still keeps on running on the server as long as the SQL Server Engine Service is not started.
Q. Are there any TRACE FLAGS for Tracking Deadlocks?
A. Yes. Use DBCC TRACEON(1204,-1). This will return the locks participating in the DEADLOCK Scenario.
DBCC TRACEON (3605,1204,-1) will Write the deadlock information in the SQL Server Error Log and at the server level, so even if you disconnect, the values are still logged, for all users.
DBCC TRACEON(3605,1222,-1) works for SQL Server 2005. Even DBCC TRACEON(1204,1222,-1) will work on SQL Server 2005 and is a Valid statement.
WARNING!! if you use 1205, this might be heavy on the SQL Server error Log, as all the commands around the lock condition might be logged.