SQL Interview: 76 Performance of temporary tables vs table variables

SQL Interview: 76 Performance of temporary tables vs table variables

This is a post in the SQL Interview series. These aren’t trick or gotcha questions, they’re just questions designed to scope out a candidate’s knowledge around SQL Server and Azure SQL Database.

Section: Administration Level: Medium

Question:

Are there situations where temporary tables will perform better than table variables?

What could cause that?

Answer:

Temporary tables have two properties that are not available to table variables:

  • Indexes - with table variables, you can have primary key constraints and unique key constraints, but not other indexes
  • Statistics - temporary tables support rich statistics, similar to tables where table variables have very limited statistics, mostly just cardinality.

2025-09-05