May 16, 2005 at 6:51 am
hi,
which of the (2) is faster or better for performace.. #tempTable or @table
i have read information on both..
thanks
May 16, 2005 at 8:20 am
It depends.
Temp tables are created in tempdb, just as any other real table. That means it is created and stored on disk with the same structures as any other table. One of the benefits of this is that it is possible to create indexes for the table, which is of course good for performance.
Table variables are created in memory only, so they are fast to create and access. You cannot create an index for them however so if you are going to be accessing them several times over and/or performing seeks in them (especially if there is a lot of data) then a temp table is often faster.
As always, test.
May 16, 2005 at 9:37 am
thanks ! thats what i was thinking but wasnt really sure...
thanks
May 16, 2005 at 10:09 am
Chris has great advice. Be sure that you test under loads to be sure which one might run better.
May 17, 2005 at 7:16 am
I agree its important to test. I performed a similar test with a variable table and a temp table. The variable table was about 20% slower than using a temp table. If your process updates the variable table frequently, then the variable table will be slightly quicker. If your just using the temp table to filter data, the my testing concluded that the temp table was 20% faster than using the variable table.
FYI: The data definition of the variable table is stored in tempdb.
August 8, 2005 at 12:21 am
Table variables are NOT created in memory. They are created in temp DB. As a rule of thumb use table variables if you are "NOT DEALING" with hugh amounts of data. You should also know the scope of the table variable before you use it.
========================================================
From Microsoft KB
A table variable is not a memory-only structure. Because a table variable might hold more data than can fit in memory, it has to have a place on disk to store data. Table variables are created in the tempdb database similar to temporary tables. If memory is available, both table variables and temporary tables are created and processed while in memory (data cache).
http://support.microsoft.com/default.aspx?scid=kb;en-us;305977
Viewing 6 posts - 1 through 5 (of 5 total)
You must be logged in to reply to this topic. Login to reply