seniorT-SQL

What is parameter sniffing in SQL Server and how do you fix it?

Updated May 17, 2026

Short answer

Parameter sniffing occurs when SQL Server compiles a plan optimized for first parameter values and reuses it for others.

Deep explanation

When a stored procedure runs, SQL Server compiles an execution plan based on initial parameter values (sniffed values). If later executions use different data distributions, the plan may become suboptimal. This leads to performance instability. Fixes include OPTIMIZE FOR, RECOMPILE, local variables, and dynamic SQL.

Unlock with a Pro subscription to view this section.

View pricing

Real-world example

No real-world example available yet.

Unlock with a Pro subscription to view this section.

Upgrade to Pro

Common mistakes

No common mistakes listed yet.

Unlock with a Pro subscription to view this section.

Upgrade to Pro

Follow-up questions

No follow-up questions available yet.

Unlock with a Pro subscription to view this section.

Upgrade to Pro

More T-SQL interview questions

View all →