# SQL Server trace flags

> SQL Server trace flags by use: effect, scope, version, the equivalent USE HINT, and the flags that help you observe the optimizer.
>
> Source : https://www.pachadata.com/en/docs/reference/trace-flags/
> Author : Rudi Bruchez · published 2026-12-02 · updated 2026-12-02
> Markdown version of the page, for tools and LLMs. The HTML page is the reference.


*Page co-written with Claude, who gathered the documentation and checked the output of the undocumented flags.*

> TL;DR :
>
> A trace flag changes an engine behavior, for the instance, the session, or a single query.
> Since SQL Server 2016 SP1, several optimizer flags have a `USE HINT` equivalent, which is
> better: its name says what it does, and it does not require the `sysadmin` role. The
> undocumented flags in the last section are for observing the optimizer on a test instance,
> never in production.


## The trace flag

A trace flag is a number that turns on an engine behavior that is otherwise out of reach: a
fix that is off by default, the legacy cardinality estimator, a diagnostic output. Microsoft
documents some of them on the page
[DBCC TRACEON - Trace Flags](https://learn.microsoft.com/sql/t-sql/database-console-commands/dbcc-traceon-trace-flags-transact-sql); the others exist in the code without being documented.

It can be turned on at three scopes:

- the whole instance, at startup (`-T2371` in the startup parameters) or on the fly with
  `DBCC TRACEON (2371, -1)`;
- the session, with `DBCC TRACEON (4136)` without `-1`;
- a single query, with `OPTION (QUERYTRACEON 9481)`. The documentation guarantees this scope
  only for the flags it marks *query*, but the engine accepts others, including those in the
  last section.

`DBCC TRACESTATUS` lists the active flags. `DBCC TRACEON` and `QUERYTRACEON` require the
`sysadmin` role; a `USE HINT` hint in a query requires none, which means you can put it in
application code. Query Store can also apply it, since SQL Server 2022 and with the `ALTER`
permission on the database; it does not accept `QUERYTRACEON`. A plan guide can also apply
`QUERYTRACEON` to a query, whichever session sends it.

The "Scope" columns follow the documentation: G for global, S for session, Q for query. Each
number links to its entry on Microsoft's page.

## Cardinality estimation and optimizer

| Flag | Effect | Scope | Equivalent or note |
|---|---|---|---|
| [9481](https://learn.microsoft.com/sql/t-sql/database-console-commands/dbcc-traceon-trace-flags-transact-sql#tf9481) | legacy estimator (model 70), whatever the compatibility level | G, S, Q | `USE HINT ('FORCE_LEGACY_CARDINALITY_ESTIMATION')`, database option `LEGACY_CARDINALITY_ESTIMATION` |
| [2312](https://learn.microsoft.com/sql/t-sql/database-console-commands/dbcc-traceon-trace-flags-transact-sql#tf2312) | estimator of the database compatibility level, and model 120 under level 120 | G, S, Q | `USE HINT ('FORCE_DEFAULT_CARDINALITY_ESTIMATION')`, equivalent from level 120 only: below that, the hint keeps model 70 (measured) |
| [4136](https://learn.microsoft.com/sql/t-sql/database-console-commands/dbcc-traceon-trace-flags-transact-sql#tf4136) | disables parameter sniffing | G, S | `USE HINT ('DISABLE_PARAMETER_SNIFFING')`, database option `PARAMETER_SNIFFING = OFF` |
| [4199](https://learn.microsoft.com/sql/t-sql/database-console-commands/dbcc-traceon-trace-flags-transact-sql#tf4199) | enables the optimizer fixes released in CUs and service packs; under an old compatibility level, also those of versions newer than that level. Fixes for wrong results do not depend on it | G, S, Q | `USE HINT ('ENABLE_QUERY_OPTIMIZER_HOTFIXES')`, database option `QUERY_OPTIMIZER_HOTFIXES` |
| [4138](https://learn.microsoft.com/sql/t-sql/database-console-commands/dbcc-traceon-trace-flags-transact-sql#tf4138) | disables the row goals of `TOP`, `FAST n`, `IN`, `EXISTS` | G, S, Q | `USE HINT ('DISABLE_OPTIMIZER_ROWGOAL')` |
| [9471](https://learn.microsoft.com/sql/t-sql/database-console-commands/dbcc-traceon-trace-flags-transact-sql#tf9471) | minimum selectivity for the filters of a table (correlation), models 120 and later | G, S, Q | `USE HINT ('ASSUME_MIN_SELECTIVITY_FOR_FILTER_ESTIMATES')`; no effect under model 70 |
| [4137](https://learn.microsoft.com/sql/t-sql/database-console-commands/dbcc-traceon-trace-flags-transact-sql#tf4137) | the same for the legacy estimator | G, S, Q | same `USE HINT` hint; no effect under models 120 and later |
| 9472 | full independence of filters (the behavior of model 70) under models 120 and later | S, Q (measured) | `USE HINT ('ASSUME_FULL_INDEPENDENCE_FOR_FILTER_ESTIMATES')`; mentioned only on the [hints page](https://learn.microsoft.com/sql/t-sql/queries/hints-transact-sql-query), which reserves it for Azure SQL Database, but it works on SQL Server 2022 and 2025 (measured) |
| [9476](https://learn.microsoft.com/sql/t-sql/database-console-commands/dbcc-traceon-trace-flags-transact-sql#tf9476) | simple containment assumption for joins instead of the base assumption | G, S, Q | `USE HINT ('ASSUME_JOIN_PREDICATE_DEPENDS_ON_FILTERS')` |
| [4139](https://learn.microsoft.com/sql/t-sql/database-console-commands/dbcc-traceon-trace-flags-transact-sql#tf4139) | histogram amendment at compile time (ascending key), whatever the state of the column | G, S, Q | `USE HINT ('ENABLE_HIST_AMENDMENT_FOR_ASC_KEYS')`; no effect under model 70 according to the documentation |
| [2389](https://learn.microsoft.com/sql/t-sql/database-console-commands/dbcc-traceon-trace-flags-transact-sql#tf2389), [2390](https://learn.microsoft.com/sql/t-sql/database-console-commands/dbcc-traceon-trace-flags-transact-sql#tf2390) | histogram amendment for keys marked ascending (2390: or unknown) | G, S, Q | no effect under models 120 and later; use 4139 |
| [9488](https://learn.microsoft.com/sql/t-sql/database-console-commands/dbcc-traceon-trace-flags-transact-sql#tf9488) | fixed guess for a multi-statement table-valued function brought down to 1 row, the value of the legacy estimator | G, S, Q | irrelevant when interleaved execution applies (level 140 and later) |
| [2453](https://learn.microsoft.com/sql/t-sql/database-console-commands/dbcc-traceon-trace-flags-transact-sql#tf2453) | recompilation of a table variable when enough rows change | G, S, Q | no effect since SQL Server 2019, replaced by deferred compilation |
| [2301](https://learn.microsoft.com/sql/t-sql/database-console-commands/dbcc-traceon-trace-flags-transact-sql#tf2301) | advanced optimizations for decision support queries | G, S, Q | |
| [9453](https://learn.microsoft.com/sql/t-sql/database-console-commands/dbcc-traceon-trace-flags-transact-sql#tf9453) | disables batch mode | G, S, Q | |
| [7470](https://learn.microsoft.com/sql/t-sql/database-console-commands/dbcc-traceon-trace-flags-transact-sql#tf7470) | additional computation of the memory granted to sorts | G, S, Q | since 2012 SP2 CU8 and 2014 CU10 |
| [9389](https://learn.microsoft.com/sql/t-sql/database-console-commands/dbcc-traceon-trace-flags-transact-sql#tf9389) | additional dynamic memory for batch mode operators | G, S | |

The values that these flags change in the estimates are measured in the
[Fixed guesses](https://www.pachadata.com/en/docs/reference/fixed-guesses/) page.

## Statistics

| Flag | Effect | Scope | Note |
|---|---|---|---|
| [2371](https://learn.microsoft.com/sql/t-sql/database-console-commands/dbcc-traceon-trace-flags-transact-sql#tf2371) | dynamic automatic update threshold, which drops as the table grows, instead of 500 + 20% of the rows | G | no effect at compatibility level 130 and later, where this threshold is the default behavior |
| [7471](https://learn.microsoft.com/sql/t-sql/database-console-commands/dbcc-traceon-trace-flags-transact-sql#tf7471) | several simultaneous `UPDATE STATISTICS` on different statistics of the same table | G | since 2014 SP1 |
| [11024](https://learn.microsoft.com/sql/t-sql/database-console-commands/dbcc-traceon-trace-flags-transact-sql#tf11024) | automatic update triggered by the counter of a partition, for an incremental statistic | G | since 2016 SP2 and 2017 CU3 |

The thresholds themselves are in the [Engine constants](https://www.pachadata.com/en/docs/reference/engine-constants/) page.

## Columnstore

| Flag | Effect | Scope | Note |
|---|---|---|---|
| [634](https://learn.microsoft.com/sql/t-sql/database-console-commands/dbcc-traceon-trace-flags-transact-sql#tf634) | disables the background compression of rowgroups (tuple mover) | G | |
| [10204](https://learn.microsoft.com/sql/t-sql/database-console-commands/dbcc-traceon-trace-flags-transact-sql#tf10204) | disables merging and recompression during a `REORGANIZE` | G, S | |
| [11631](https://learn.microsoft.com/sql/t-sql/database-console-commands/dbcc-traceon-trace-flags-transact-sql#tf11631) | cleanup threshold for deleted rows computed on the current rows of the rowgroup | G | since 2019 CU9 |
| [11634](https://learn.microsoft.com/sql/t-sql/database-console-commands/dbcc-traceon-trace-flags-transact-sql#tf11634) | cleanup threshold for deleted rows brought down from 10% to 1%: 1% of a million rows, or 1% of the rows of the rowgroup with 11631 ([Microsoft support blog post](https://techcommunity.microsoft.com/blog/sqlserversupport/new-trace-flags-for-better-maintenance-of-deleted-rows-in-columnstore-index/2127034)) | G | since 2019 CU9 |

## Log, backup, and recovery

| Flag | Effect | Scope | Note |
|---|---|---|---|
| [3226](https://learn.microsoft.com/sql/t-sql/database-console-commands/dbcc-traceon-trace-flags-transact-sql#tf3226) | suppresses the messages of successful backups and restores, in the error log and the event log | G | |
| [3502](https://learn.microsoft.com/sql/t-sql/database-console-commands/dbcc-traceon-trace-flags-transact-sql#tf3502) | writes the steps of checkpoints to the error log | G, S | |
| [3468](https://learn.microsoft.com/sql/t-sql/database-console-commands/dbcc-traceon-trace-flags-transact-sql#tf3468) | disables indirect checkpoint on `tempdb` | G | since 2016 SP1 CU5 and 2017 CU1 |
| [3459](https://learn.microsoft.com/sql/t-sql/database-console-commands/dbcc-traceon-trace-flags-transact-sql#tf3459) | disables parallel *redo* | G | since 2016 |
| [3261](https://learn.microsoft.com/sql/t-sql/database-console-commands/dbcc-traceon-trace-flags-transact-sql#tf3261), [3262](https://learn.microsoft.com/sql/t-sql/database-console-commands/dbcc-traceon-trace-flags-transact-sql#tf3262) | forbids differential (3261) or full (3262) backups on a secondary replica of an availability group | G | SQL Server 2025 |
| [610](https://learn.microsoft.com/sql/t-sql/database-console-commands/dbcc-traceon-trace-flags-transact-sql#tf610) | minimally logged inserts into indexed tables | G, S | unnecessary since 2016 |
| [692](https://learn.microsoft.com/sql/t-sql/database-console-commands/dbcc-traceon-trace-flags-transact-sql#tf692) | disables fast insert for bulk loads | G, S | since 2016 |

## Locks, memory, and diagnostics

| Flag | Effect | Scope | Note |
|---|---|---|---|
| [1204](https://learn.microsoft.com/sql/t-sql/database-console-commands/dbcc-traceon-trace-flags-transact-sql#tf1204), [1222](https://learn.microsoft.com/sql/t-sql/database-console-commands/dbcc-traceon-trace-flags-transact-sql#tf1222) | writes deadlocks to the error log (1222: in XML) | G | the [`system_health`](https://learn.microsoft.com/sql/relational-databases/extended-events/use-the-system-health-session) session already captures them |
| [1211](https://learn.microsoft.com/sql/t-sql/database-console-commands/dbcc-traceon-trace-flags-transact-sql#tf1211) | disables all lock escalation | G, S | the documentation recommends 1224 instead |
| [1229](https://learn.microsoft.com/sql/t-sql/database-console-commands/dbcc-traceon-trace-flags-transact-sql#tf1229) | disables lock partitioning | G | |
| [174](https://learn.microsoft.com/sql/t-sql/database-console-commands/dbcc-traceon-trace-flags-transact-sql#tf174) | raises the plan cache buckets from 40,009 to 160,001 on 64-bit | G | at startup |
| [8032](https://learn.microsoft.com/sql/t-sql/database-console-commands/dbcc-traceon-trace-flags-transact-sql#tf8032) | goes back to the cache limits of SQL Server 2005 | G | |
| [2451](https://learn.microsoft.com/sql/t-sql/database-console-commands/dbcc-traceon-trace-flags-transact-sql#tf2451) | equivalent of the last actual plan in `sys.dm_exec_query_plan_stats` | G | since 2019; the database option `LAST_QUERY_PLAN_STATS` does the same |
| [7412](https://learn.microsoft.com/sql/t-sql/database-console-commands/dbcc-traceon-trace-flags-transact-sql#tf7412) | lightweight profiling of execution statistics | G | since 2016 SP1; no effect since 2019, where lightweight profiling is on by default |
| [3605](https://learn.microsoft.com/sql/t-sql/database-console-commands/dbcc-traceon-trace-flags-transact-sql#tf3605) | redirects trace messages to the error log | G, S | debugging flag |
| [2528](https://learn.microsoft.com/sql/t-sql/database-console-commands/dbcc-traceon-trace-flags-transact-sql#tf2528) | disables the parallelism of `DBCC CHECKDB` | G, S | |
| [2562](https://learn.microsoft.com/sql/t-sql/database-console-commands/dbcc-traceon-trace-flags-transact-sql#tf2562) | `DBCC CHECKDB` in a single batch, whatever the number of indexes | G, S | |
| [1117](https://learn.microsoft.com/sql/t-sql/database-console-commands/dbcc-traceon-trace-flags-transact-sql#tf1117), [1118](https://learn.microsoft.com/sql/t-sql/database-console-commands/dbcc-traceon-trace-flags-transact-sql#tf1118) | growth of all the files of a filegroup; allocations in uniform extents | G | no effect since 2016, replaced by `AUTOGROW_ALL_FILES` (filegroup) and `MIXED_PAGE_ALLOCATION` (database) |
| [15097](https://learn.microsoft.com/sql/t-sql/database-console-commands/dbcc-traceon-trace-flags-transact-sql#tf15097) | enables AVX-512 support | G, S | since 2022 |

## Undocumented flags for observing the optimizer

These flags have no entry in the documentation. They write the internal state of the
optimizer and help you understand it, on a test instance. Their output reaches the Messages
tab only if flag 3604 is on, for the session (`DBCC TRACEON (3604)`) or for the query
(`QUERYTRACEON 3604`); without it, nothing is displayed. The excerpts below come from SQL
Server 2025 CU11, with the query of the example at the bottom of the page.

| Flag | What it writes | Start of the output |
|---|---|---|
| 3604 | sends the output of `DBCC` and of the flags below to the client | (no output of its own) |
| 8605 | the converted tree, before simplification | `*** Converted Tree: ***` |
| 8606 | the input tree, then the trees of simplification: *Simplified Tree*, *Join-collapsed Tree*, before and after the normalization of projections | `*** Input Tree: ***` |
| 8607 | the output physical tree | `*** Output Tree: ***` |
| 7352 | the final tree of the query, operators and columns | `Compute Scalar Compute Scalar (0)` |
| 8608 | the initial memo, with the cardinality of each group | `--- Initial Memo Structure ---` |
| 8615 | the final memo, with the cost of each alternative | `--- Final Memo Structure ---` |
| 8619 | the transformation rules applied | `Apply Rule: JoinCommute - A JOIN B -> B JOIN A` |
| 8621 | the rules applied and the tree they produce | `***** Rule applied: GbAggOnPrj ...` |
| 8675 | the end of each stage: simplification, exploration, search phases with their number of tasks and their cost | `End of simplification, time: 0 net: 0 ...` |
| 2363 | the computation of each selectivity, models 120 and later | `Begin selectivity computation` |
| 2372 | the memory used at each step of the compilation | `Memory before NNFConvert: 8` |

Two others change the plan instead of writing it:

| Flag | Measured effect | Equivalent |
|---|---|---|
| 8649 | parallel plan even below the cost threshold: the plan of the join goes from serial to parallel | `USE HINT ('ENABLE_PARALLEL_PLAN_PREFERENCE')`, also undocumented and absent from `sys.dm_exec_valid_use_hints`, but accepted |
| 8757 | removes the trivial plan: `StatementOptmLevel` goes from `TRIVIAL` to `FULL` | |

Example of output:

```sql
USE PachaDataFormation;
DBCC TRACEON (3604);   -- output to the Messages tab, for this session

SELECT c.Nom, COUNT(*) AS nb
FROM Contact.Contact AS c
JOIN Inscription.Inscription AS i ON i.ContactId = c.ContactId
GROUP BY c.Nom
OPTION (RECOMPILE, QUERYTRACEON 8606, QUERYTRACEON 8607);

DBCC TRACEOFF (3604);
```

`QUERYTRACEON` requires the `sysadmin` role. `RECOMPILE` forces a compilation: without it,
a query whose plan is in the cache does not go through the optimizer and writes nothing.



---

## About the author

Rudi Bruchez, independent SQL Server consultant since 2006: performance audits, tuning, migrations, high availability and training. For an audit or hands-on help on your server: https://www.pachadata.com/en/contact/ (remote audit: https://www.pachadata.com/en/services/remote-sql-server-audit/).
