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
-
i am not sure this is an exact duplicate of the question mentioned. the post given in the link mentions the perf differences with respect to record counts. However in my case that record count does not appear to be the factor as there is only one record being updateduser55474– user554742011年05月10日 02:36:33 +00:00Commented May 10, 2011 at 2:36
2 Answers 2
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
5 Comments
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.
2 Comments
tempDB
- just like a temp table. No real big difference here...