Trace flags are used to temporarily enable or disable specific SQL Server database functions, allowing you to change default database behavior or to observe hidden database behavior, and will remain in effect until they are either manually turned off or SQL Server is restarted. Keep in mind that most trace flags are undocumented and Microsoft can and will change the behavior of the flag between SQL Server versions, service packs or hot fixes.
Trace flags can either be set upon startup of SQL Server by using the -Ttrace# option upon SQL Server startup, or by using the DBCC TRACEON console command. Either way, the trace flag will be active until SQL Server is restarted or you use the DBCC TRACEOFF console command to turn the trace flag off.
Trace flags can be a good investigation tool to find that hidden problem or determine how something is really behaving, but it is recommended that you carefully investigate the behavior of a undocumented trace flag before you implement it in your environments (currently only trace flags 230, 1204, 2528, and 3205 are documented in SQL Server 2000 Books Online). A through search of Microsoft’s Knowledge Based articles will help in your investigation the current behavior of some trace flags.
The following table is taken from Transact-SQL Language Reference Guide and explains the behavior of a few of the currently documented and undocumented trace flags available for SQL Server 7.0 and 2000.
|Sets trace flags for all client connections, rather than for a single client connection. Because trace flags set using the -T command-line option automatically apply to all connections, this trace flag is used only when setting trace flags using DBCC TRACEON and DBCC TRACEOFF.
|Disables line number information for syntax errors.
|Interprets numbers with a decimal point as float instead of decimal.
|Report when a statistics-dependent stored procedure is being recompiled as a result of AutoStat.
|Provides backward compatibility for the setuser statement.
|SET QUOTED IDENTIFIER ON.
|Provides backward compatibility for correlated subqueries where non-ANSI-standard results are desired.
|The behavior of SQL Server is now more consistent because nullability checks are made at run time and a nullability violation results in the command terminating and the batch or transaction process continuing.
|Disables checking for allowed interim constraint violations. By default, SQL Server checks for and allows interim constraint violations. An interim constraint violation is caused by a change that removes the violation such that the constraint is met, all within a single statement and transaction. SQL Server checks for interim constraint violations for self-referencing DELETE statements, INSERT, and multi-row UPDATE statements. This checking requires more work tables. With this trace flag you can disallow interim constraint violations, thus requiring fewer work tables.
|Will invoke a print algorithm on the XML output before returning it to make the XML result more readable.
|Prints the versioning information about extended stored procedure dlls.
|Prints information about whether the statistics page is used, the actual selectivity (if available), and what SQL Server estimated the physical and logical I/O would be for the indexes. Trace flag 302 should be used with trace flag 310 to show the actual join ordering.
|Prints information about join order. Index selection information is also available in a more readable format using SET SHOWPLAN_ALL, as described in the SET statement.
|Prints information about the cost of using a non-clustered index or a sort to process an ORDER BY clause.
|Prints information about the estimated and actual cost of sorts.
|Enables full output when using the SET SHOWPLAN_ALL option, which gives detailed information about joins.
|Enforces SQL-92 standards regarding null values for comparisons between variables and parameters. Any comparison of variables and parameters that contain a NULL always results in a NULL.
|Disables read ahead for the server.
|Disables read ahead for the current connection.
|Limits the amount of Lazy Write activity in SQL Server 2000.
|Forces allocation to use free pages for text or image data and maintain efficiency of storage.
|Prints lock information (the process ID and type of lock requested).
|Returns the type of lock participating in the deadlock and the current command affect by the deadlock.
|Returns more detailed information about the command being executed at the time of a deadlock.
|Used to complement flag 1204 by displaying other locks held by deadlock parties
|Turns on the unpacking and checking of remote procedure call (RPC) information in Open Data Services. Used only when applications depend on the old behavior.
|Prints information when a temporary table is created or dropped.
|Allows you to configure SQL Server with network-based database files.
|Prevents DBCC TRACEON 208, SPID 10 errors from appearing in the error log.
|Disables parallel non-clustered index checking for DBCC CHECKTABLE.
|Used with DBCC CHECKTABLE.html to see the total count of ghost records in a table
|Disables parallel checking of objects by DBCC commands.
|Sets the @@ERROR system function to 50000 for RAISERROR messages with severity levels of 10 or less. When disabled, sets the @@ERROR system function to 0 for RAISERROR messages with severity levels of 10 or less.
|Causes SQL Server to bypass checking for free space.
|Cause LogMgr::ValidateBackedupBlock to be skipped during backup and restore operations.
|Disables hardware compression for tape drivers.
|Disables the read ahead that is used by the recovery operation during roll forward operations.
|Prints a message to the log at the start and end of each checkpoint.
|Indicates whether the checkpoint at the end of automatic recovery was skipped for a database (this applies only to read-only databases).
|Records all error and warning messages sent to the client.
|Sends trace output to the client. Used only when setting trace flags with DBCC TRACEON and DBCC TRACEOFF.
|Sends trace output to the error log. (If you start SQL Server from the command prompt, the output also appears on the screen.)
|Skips automatic recovery (at startup) for all databases.
|Skips automatic recovery (at startup) for all databases except the master database.
|Skips the creation of the tempdb database at startup. Use this trace flag if the device or devices on which tempdb resides are problematic or problems exist in the model database.
|Turns on tracking of the CPU data for the sysprocesses table.
|Eliminates the sending of DONE_IN_PROC messages to the client for each statement in a stored procedure. This is similar to the session setting of SET NOCOUNT ON, but when set as a trace flag, every client session is handled this way.
|Bypasses automatically started procedures.
|Prints both a byte and ASCII representation of the receive buffer. Used when you want to see what queries a client is sending to SQL Server. You can use this trace flag if you experience a protection violation and want to determine which statement caused it. Typically, you can set this flag globally or use SQL Server Enterprise Manager. You can also use DBCC INPUTBUFFER.
|Prints both a byte and ASCII representation of the send buffers (what SQL Server sends back to the client). You can also use DBCC OUTPUTBUFFER.
|Traces the SQL commands coming in from the client. The output destination of the trace flag is controlled with the 3605/3604 trace flags.
|Retrieves extended information about any error you encounter when you execute a distributed query.
|Dynamic cursors are used by default on forward-only cursors. Dynamic cursors are faster than in earlier versions and no longer require unique indexes. This flag disables the dynamic cursor enhancements and reverts to version 6.0 behavior.
|Disables the caching of cursor plans for extended stored procedures.
|Enables version 6.x handling of return codes when calling dbcursorfetchex and the resulting cursor position follows the end of the cursor result set.
|Reverts to the SQL Server 7.0 behavior of closing nonstatic cursors regardless of the SET CURSOR_CLOSE_ON_COMMIT state in SQL Server 2000.
|Replicates all UPDATE commands as DELETE/INSERT pairs at the publisher.
|Supports stored procedure execution with a user specified owner name for SQL Server subscribers or without owner qualification for heterogeneous subscribers in SQL Server 2000.
|Enables singleton updates for Transactional Replication, released with SQL Server 2000 Service Pack 1.
|Allows you to use a savepoint within a distributed transaction.
|Prevents the SQL Server optimizer from using a Hash Match Team operator.
|Used to disable query parallelism.
|Dumps information into the error log when AutoStat has been run.
|Allows DELETE, INSERT, and UPDATE statements to honor the SET ROWCOUNT ON setting when enabled.
|Logs every two-digit year conversion to a four-digit year.
To find out more about any of the Transact-SQL statements, commands, stored procedures or system tables referenced in this article, please download and purchase a copy of Transact-SQL Language Reference Guide from my website www.TransactSQL.Com.
Copyright 2002 by Randy Dyess, All rights Reserved.]]>