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

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

    It surprises me that no one mentioned the key difference between these two is that the temp table supports parallel insert while the table variable doesn't. You should be able to see the difference from the execution plan. And here is the video from SQL Workshops on Channel 9.

    This also explains why you should use a table variable for smaller tables, otherwise use a temp table, as SQLMenace answered before.

提交回复
热议问题