SQL Server Interview Question #173

What is the difference between a temporary table and a table variable?

Database Design, Normalization & Advanced SQL Senior Advanced

Detailed Explanation

A #temporary table is created in tempdb, supports flexible indexing and statistics, and is often effective for larger intermediate result sets. A table variable has batch/procedure scope and historically had more limited cardinality information, although newer SQL Server versions can improve optimization through deferred compilation.

Neither option is universally faster. The correct choice depends on row count, reuse, indexing needs, query complexity, SQL Server version, recompilation behavior, and the actual execution plan.