DBCC TRACEON (Transact-SQL)

**APPLIES TO:** ![yes](media/yes.png)SQL Server (starting with 2008) ![no](media/no.png)Azure SQL Database ![no](media/no.png)Azure SQL Data Warehouse ![no](media/no.png)Parallel Data Warehouse

Enables the specified trace flags.

Topic link icon Transact-SQL Syntax Conventions

Syntax

DBCC TRACEON ( trace# [ ,...n ][ , -1 ] ) [ WITH NO_INFOMSGS ]  

Arguments

trace#
Is the number of the trace flag to turn on.

n
Is a placeholder that indicates multiple trace flags can be specified.

-1
Switches on the specified trace flags globally.

WITH NO_INFOMSGS
Suppresses all informational messages.

Remarks

On a production server, to avoid unpredictable behavior, we recommend that you only enable trace flags server-wide by using one of the following methods: - Use the -T command-line startup option of Sqlservr.exe. This is a recommended best practice because it makes sure that all statements will run with the trace flag enabled. These include commands in startup scripts. For more information, see sqlservr Application.
- Use DBCC TRACEON (trace# [,.n],-1) only while users or applications are not concurrently running statements on the system.

Trace flags are used to customize certain characteristics by controlling how SQL Server operates. Trace flags, after they are enabled, remain enabled in the server until disabled by executing a DBCC TRACEOFF statement. In SQL Server SQL Server there are two types of trace flags: session and global. Session trace flags are active for a connection and are visible only for that connection. Global trace flags are set at the server level and are visible to every connection on the server. To determine the status of trace flags, use DBCC TRACESTATUS. To disable trace flags, use DBCC TRACEOFF.

After turning on a trace flag that affects query plans, execute DBCC FREEPROCCACHE; so that cached plans are recompiled using the new plan-affecting behavior.

Result Sets

DBCC TRACEON returns the following result set (message):

DBCC execution completed. If DBCC printed error messages, contact your system administrator.  

Permissions

Requires membership in the sysadmin fixed server role.

Examples

The following example disables hardware compression for tape drivers, by switching on trace flag 3205. This flag is switched on only for the current connection.

DBCC TRACEON (3205);  
GO  

The following example switches on trace flag 3205 globally.

DBCC TRACEON (3205, -1);  
GO  

The following example switches on trace flags 3205, and 260 globally.

DBCC TRACEON (3205, 260, -1);  
GO  

See Also

DBCC (Transact-SQL)
DBCC TRACEOFF (Transact-SQL)
DBCC TRACESTATUS (Transact-SQL)
Trace Flags (Transact-SQL)
Enable plan-affecting SQL Server query optimizer behavior that can be controlled by different trace flags on a specific-query level