Which is better temporary table or table variable?

Which is better temporary table or table variable?

As we can see from the results above a temporary table generally provides better performance than a table variable. The only time this is not the case is when doing an INSERT and a few types of DELETE conditions.

When does SQL Server temp table increase performance?

The only time this is not the case is when doing an INSERT and a few types of DELETE conditions. This increase in performance is especially evident when dealing with larger data sets as the ability to create indexes on the temporary table speeds up query execution significantly.

How to compare temp table and CTE in SQL Server?

In this tip we will go through a few simple SELECT queries in order to compare the performance in SQL Server using each type of object, temp table, table variable and a CTE, to store the temporary data. We will compare the execution times of each query as well as the system resources needed to complete each operation.

Can a temp table be a performance bottleneck?

Tempdb can be a performance bottleneck for many applications. Workloads that intensively use table-valued parameters (TVPs), table variables and temp tables can cause contention on things like metadata and page allocation, and result in a lot of IO activity that you would rather avoid.

How can I get performance to increase without temporary tables?

The simple thing to try is to pick an expensive query (for instance, a long-running one, or one that’s executed many times per second) and remove one or more of the temporary tables to see whether performance increases without them. And if so, there’s your proof to show the intransigents!

Is it possible to run a temp table really fast?

Temp tables are in memory (unless they’re too big), so in theory they should be REALLY fast. But it’s usually not. As a rule of thumb, try to stay away from temp tables, unless that is the only solution. Can you give us some more information about what you’re trying to do?