// sql server · query planner

PARAMETER_SNIFFING

Whether plans are compiled for the parameter values of the first execution.

預設
ON
Range
ON, OFF, PRIMARY (secondary only)
Restart needed
否
Default checked on
SQL Server 2025

其作用

OFF compiles for average density, as if every query had OPTIMIZE FOR UNKNOWN. SQL Server 2022's parameter-sensitive plan optimization (compatibility 160+) is a finer-grained alternative.

預設值

ON. ON (SQL Server 2025).

Check the current value

-- run in the database you want to check
SELECT name, value, value_for_secondary, is_value_default
FROM sys.database_scoped_configurations
WHERE name = 'PARAMETER_SNIFFING';

Change it

-- run in the database to change
ALTER DATABASE SCOPED CONFIGURATION SET PARAMETER_SNIFFING = OFF;

No restart. It applies to the current database, to queries compiled after the change; run it in each database that needs it.

When to change it

Rarely database-wide. Prefer fixing specific queries with OPTION (RECOMPILE), OPTIMIZE FOR or Query Store plan forcing.

What can go wrong

Average-density plans can be worse for every value than a sniffed plan was for most.

Questions about PARAMETER_SNIFFING

What is the default value of PARAMETER_SNIFFING in SQL Server?

ON. ON (SQL Server 2025).

Does changing PARAMETER_SNIFFING require a restart?

No. No restart. It applies to the current database, to queries compiled after the change; run it in each database that needs it.

When should I change PARAMETER_SNIFFING?

Rarely database-wide. Prefer fixing specific queries with OPTION (RECOMPILE), OPTIMIZE FOR or Query Store plan forcing.

Back to all SQL Server settings, or check the SQL Server manual for every option.

// one client for every engine

Check PARAMETER_SNIFFING on your own server

SQLly runs the query above against SQL Server and the other engines in this reference, from one desktop app on macOS, Windows and Linux.