开发者

SQL server table variable vs temp table [duplicate]

开发者 https://www.devze.com 2023-03-03 20:00 出处:网络
This question already has answers here: 开发者_运维技巧Closed 11 years ago. Possible Duplicate: What's the difference between a temp table and table variable in SQL Server?
This question already has answers here: 开发者_运维技巧 Closed 11 years ago.

Possible Duplicate:

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

I am using a table variable to store the aggregate results of a query.

The query is as below

update @results 
set col1 = totals  
from ( select sum(x) as totals from ......) 
where id = 1

If I use a temp table the query runs much faster.

Should the use of table variable or temp table matter in the query above?

Am I overlooking something?

thanks


It really depends on the amount of records. Table variables perform much better on smaller records sets. Here is a good blog post with some benchmarking: http://sqlnerd.blogspot.com/2005/09/temp-tables-vs-table-variables.html


table variables are fine until you get more than 100 results. If you are expecting 100 results or more then you should switch to a temp table for efficiency.

0

精彩评论

暂无评论...
验证码 换一张
取 消