A dashboard application sends the following Transact-SQL statement to the OLTP database dozens of times each minute, changing only the literal value in the WHERE clause that comes from the user interface:
SELECT customer_id, order_date, total_amount
FROM sales.orders
WHERE customer_id = 12345;
The DBA observes that every execution causes SQL Server to parse and compile a new plan, and the plan cache is filling up with single-use plans for this query pattern. Without altering table structures or adding new indexes, which basic query optimization technique is most likely to cut CPU time by allowing the same execution plan to be reused across calls?
Add the WITH (NOLOCK) table hint to the orders table.
Submit the statement as a parameterized query that passes the customer_id as a bind variable.
Copy the orders into a temporary table and run the filter against the temp table instead.
Append the OPTION (RECOMPILE) hint to force the optimizer to build a fresh plan each time.
Submitting the statement as a parameterized query replaces the literal value with a bind variable (for example, WHERE customer_id = @cust_id). Because the SQL text remains constant, the optimizer can recognize subsequent executions as the same logical query and reuse the compiled plan, eliminating unnecessary parse/compile overhead. Adding the WITH (NOLOCK) hint affects locking, not compilation. Copying rows to a temporary table incurs extra I/O and still requires a compilation for each run. Forcing OPTION (RECOMPILE) tells SQL Server to discard the cached plan after each execution, increasing, not decreasing, CPU cost.
Ask Bash
Bash is our AI bot, trained to help you pass your exam. AI Generated Content may display inaccurate information, always double-check anything important.
What is a parameterized query, and how does it help optimize SQL execution?
Open an interactive chat with Bash
What is the purpose of the plan cache in SQL Server?
Open an interactive chat with Bash
How is the `WITH (NOLOCK)` table hint different from using parameterized queries?
Open an interactive chat with Bash
CompTIA Data+ DA0-002 (V2)
Data Acquisition and Preparation
Your Score:
Report Issue
Bash, the Crucial Exams Chat Bot
AI Bot
Loading...
Loading...
Loading...
Pass with Confidence.
IT & Cybersecurity Package
You have hit the limits of our free tier, become a Premium Member today for unlimited access.
Military, Healthcare worker, Gov. employee or Teacher? See if you qualify for a Community Discount.
Monthly
$19.99 $11.99
$11.99/mo
Billed monthly, Cancel any time.
$19.99 after promotion ends
3 Month Pass
$44.99 $26.99
$8.99/mo
One time purchase of $26.99, Does not auto-renew.
$44.99 after promotion ends
Save $18!
MOST POPULAR
Annual Pass
$119.99 $71.99
$5.99/mo
One time purchase of $71.99, Does not auto-renew.
$119.99 after promotion ends
Save $48!
BEST DEAL
Lifetime Pass
$189.99 $113.99
One time purchase, Good for life.
Save $76!
What You Get
All IT & Cybersecurity Package plans include the following perks and exams .