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

后端 未结 12 1277
抹茶落季
抹茶落季 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:45

    For all of you who believe the myth that temp variables are in memory only

    First, the table variable is NOT necessarily memory resident. Under memory pressure, the pages belonging to a table variable can be pushed out to tempdb.

    Read the article here: TempDB:: Table variable vs local temporary table

提交回复
热议问题