Table of four ways to ask for the 10 Front tickets. A literal value gets an index seek with a key lookup and 32 reads. A variable with no hint gets a clustered index scan, an estimate of 25,005 rows and 1,435 reads. OPTIMIZE FOR and RECOMPILE both return to the seek and 32 reads

Query Hint Basics: Why a Variable Scans and OPTIMIZE FOR Seeks

Query hint basics start with one idea: a query hint is an instruction you add to one statement in the OPTION clause. This post builds a table of 50,010 tickets, shows a seek for a literal value, a scan for the same value in a variable, and a seek again with OPTIMIZE FOR and with RECOMPILE. It also shows what the hint costs when the value changes. Every number comes from SQL Server 2025.

Read More