What's the difference between a temp table and table variable in SQL Server?

后端 未结 12 1125
抹茶落季
抹茶落季 2020-11-22 05:03

In SQL Server 2005, we can create temp tables one of two ways:

declare @tmp table (Col1 int, Col2 int);

or

create table #tm         


        
12条回答
  •  感情败类
    2020-11-22 05:24

    @wcm - actually to nit pick the Table Variable isn't Ram only - it can be partially stored on disk.

    A temp table can have indexes, whereas a table variable can only have a primary index. If speed is an issue Table variables can be faster, but obviously if there are a lot of records, or the need to search the temp table of a clustered index, then a Temp Table would be better.

    Good background article

提交回复
热议问题