SQL Flow Field Guide

QUERY HINT KEEP PLAN

Catalog support for SQL Server 2022 (16.x) and 2025 (17.x)

Changes the recompilation thresholds for temporary tables, and makes them identical to the thresholds for permanent tables.

What changes

Input
none
Output or change
none

Syntax at a glance

OPTION ( KEEP PLAN )

Work example

A measured query issue may justify testing QUERY HINT KEEP PLAN against the optimizer's default choice.

Capture the current plan, rows, reads, and elapsed time. Change one hint in a test copy and compare the same parameter values.

Check your work QUERY HINT KEEP PLAN. The intended plan behavior for QUERY HINT KEEP PLAN is visible and the result rows are unchanged across the comparison.

Open Microsoft Learn for full syntax, permissions, and details for your version.