Trace flags can be set on / off for the current connection only, using the following T-SQL code:
Traces can be set on / off globally (i.e. for ALL connections to the SQL Engine) with the addition of the -1 argument at the end:-- Turn on trace flag 1234DBCC TRACEON (1234);GO-- Turn off trace flag 1234DBCC TRACEOFF (1234);GO
Multiple traces can be switched on by listing them within the parenthesis:-- Turn on trace flag 1234, globallyDBCC TRACEON (1234, -1);GO
You can see which trace flags are currently active as follows (if none are active, a message of "DBCC execution completed. If DBCC printed error messages, contact your system administrator" will appear):-- Turn on trace flags 1234, 2345 and 3456DBCC TRACEON (1234, 2345, 3456);GO
Only members of the sysadmin fixed group can switch traces on / off.-- Check status of current trace flagsDBCC TRACESTATUS
Useful Trace Flags:
1222: Examine deadlocks
1204: Write deadlock information to SQL Server log
Trace flag resources:
MSDN: https://msdn.microsoft.com/en-us/library/ms188396.aspx
SQL Mag: http://sqlmag.com/sql-server/investigating-trace-flags
Stack Exchange: http://dba.stackexchange.com/questions/27704/sql-server-concise-list-of-trace-flags
No comments:
Post a Comment