473,372 Members | 993 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,372 software developers and data experts.

The age old argument of Temp table vs Table variable

Hi All,

Hope someone can help me...

Im trying to highlight the advantages of using table variables as
apposed to temp tables within single scope.
My manager seems to believe that table variables are not advantageous
because they reside in memory.
He also seems to believe that temp tables do not use memory...

Does anyone know how SQL server could read data from a temp table
without passing the data contained therein through memory???

Is this a valid advantage/disadvantage of table variables VS temp
tables?

Jan 26 '07 #1
2 5511
Am 26 Jan 2007 05:43:42 -0800 schrieb Burbletrack:
Hi All,

Hope someone can help me...

Im trying to highlight the advantages of using table variables as
apposed to temp tables within single scope.
My manager seems to believe that table variables are not advantageous
because they reside in memory.
He also seems to believe that temp tables do not use memory...

Does anyone know how SQL server could read data from a temp table
without passing the data contained therein through memory???

Is this a valid advantage/disadvantage of table variables VS temp
tables?
Maybe this can help you a little bit:
http://support.microsoft.com/kb/305977/EN-US/

bye,
Helmut
Jan 26 '07 #2
Burbletrack (er**********@gmail.com) writes:
Im trying to highlight the advantages of using table variables as
apposed to temp tables within single scope.
My manager seems to believe that table variables are not advantageous
because they reside in memory.
He also seems to believe that temp tables do not use memory...

Does anyone know how SQL server could read data from a temp table
without passing the data contained therein through memory???

Is this a valid advantage/disadvantage of table variables VS temp
tables?
I could probably write several hundred lines about temp tables vs.
table variables, and you would still be confused.

I have been able to achieve radical performance enhancements by replacing
a temp table with a table variable. And I have been able to achieve
radical performance enhancements by replacing a table variable with
a temp table.

As for memory or not - that's a non-starter. A temp table is a real
table on disk, but if you query it, it will be brought into cache.
A table variable may in memory to start with - or may be not. But it
can spill to disk.

No, what is the overall important is that temp table has statistics,
table variables has not. Not having statistics means that they cannot
cause recompiles, which can be costly, particularly on SQL 2000 where
the entire procedure is always recompiled. But not having stastics
means that the optimizer will have to make standard assumptions which
can result in poor query plans.

If I am to give a recommendation it is that if you expect a small
number of rows, a few thousand may be, use a table variable. If you
exepct many rows use a temp table. But always be prepared to change
if the chosen strategy backfires.

Also, inserting into a table variable precludes parallelism. This
can sometimes be an issue.

--
Erland Sommarskog, SQL Server MVP, es****@sommarskog.se

Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/pro...ads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodinf...ons/books.mspx
Jan 26 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: juan_av | last post by:
Hi, I need to know, how I can to do to create a table in PHP, taking de name for this table from a form variable. Thanks
1
by: boonkit | last post by:
I try to get better performance by implementing this: http://dev.mysql.com/doc/mysql/en/alter-table.html "ORDER BY allows you to create the new table with the rows in a specific order. Note...
2
by: David | last post by:
Hi, Is this possible & How ? We manufacture products. Each product has a list of items which can be packed at our production facility. A Picking List. Certain customers may require certain...
1
by: S?ren Gammelmark | last post by:
Hi I have been searching the web and comp.lang.c of a method of using variable-argument function pointers and the like. And some of the questions arising in this post are answered partly in...
2
by: Troy | last post by:
I have been trying for 2 weeks to figure out how to implement a table as a member variable that the user can setup with the property designer with no luck. The code below adds the table to the...
3
by: a | last post by:
Hey gang! I have a specific problem, but a general answer may help. I am building a web app which will display multiple UserControls on the screen. I want to put them in a table that is X...
2
by: hisham123 | last post by:
hi, I Wrote one stored procedure in which i declare one variable as Table then i stored in that table type variable select * from emp so now my table contain one sql statement by 4 rows...
1
by: islandtalker | last post by:
Hi, In a stored procedure (MS SQL) I want to update a table to Add columns to it, and then update those new columns with data from a variable. The problem is that, after updating the table I...
2
by: salzan | last post by:
I create a temp table (using ADOX) and populate it from my form based on various conditions. Now, I'd like to report the results using Reports. I have a query and a report and they work fine. What...
5
by: JonHuff | last post by:
Here is my code. I am trying to INSERT INTO "Master_Table" field "Edited_By" the variable value of "Editor" "Editor" is the User Name of the person logged onto that computer Code Option...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.