70-465 · Question #71
You need to recommend a solution to minimize the amount of time it takes to execute USP_2. What should you recommend?
The correct answer is C. A temporary table. To minimize execution time of a stored procedure (USP_2), using a temporary table allows intermediate results to be stored, indexed, and reused efficiently within the session.
Question
Options
- AA database snapshot
- BA table variable
- CA temporary table
- DSnapshot isolation
How the community answered
(49 responses)- A6% (3)
- B4% (2)
- C80% (39)
- D10% (5)
Why each option
To minimize execution time of a stored procedure (USP_2), using a temporary table allows intermediate results to be stored, indexed, and reused efficiently within the session.
A database snapshot provides a read-consistent point-in-time view of a database for reporting or recovery purposes, but it does not optimize the internal execution of a stored procedure.
A table variable stores data in memory-scoped to a batch or procedure, but it does not maintain statistics and is treated as having a single-row estimate by the query optimizer, which can lead to poor execution plans on larger datasets compared to temporary tables.
Temporary tables (created with #tablename) are stored in tempdb and support indexes, statistics, and multiple references within a stored procedure, which can significantly reduce execution time by allowing the query optimizer to use better execution plans. Unlike table variables, temp tables allow statistics to be gathered, enabling more efficient joins and filtering on large datasets. This makes them ideal for breaking complex queries into optimized steps within a stored procedure like USP_2.
Snapshot isolation is a transaction isolation level that reduces blocking by using row versioning, but it does not directly improve the execution performance or speed of a stored procedure's query logic.
Concept tested: Optimizing stored procedure performance using temporary tables
Source: https://learn.microsoft.com/en-us/sql/t-sql/statements/create-table-transact-sql?view=sql-server-ver16#temporary-tables
Topics
Community Discussion
No community discussion yet for this question.