473,772 Members | 2,411 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 5550
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**********@g mail.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****@sommarsk og.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
1858
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
17141
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 that the table does not remain in this order after inserts and deletes. This option is mainly useful when you know that you are mostly going to query the rows in a certain order; by using this option after big changes to the table, you might be able...
2
1496
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 packing items to be omitted from certain products. My products table is linked to a ProductPacking Table 1 to Many.
1
2205
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 these posts, but I ask mainly for a way to found a way to solve this problem. I'm a hobbyist so there might be an alltogether better solution to the problem, so please come with any solution you might think of. I'm open to ideas. --- And i'm not...
2
2568
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 property designer, however it will not write the HTML associated with the TABLE within the custom server control tags unless you change the font property within the table. For instance you can set the ID of the table and its height and width then...
3
1455
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 Columns by however many rows it takes to complete the list. I essentially need to add dim a new row, then a new cell, and continue adding cells to the row until i get to the max_rows property, then add that row to the table, dim a new row, and...
2
3735
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 now i want to execute the sql statement how (MS SQL SERVER 2000)
1
2845
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 add a GO, the variable value is loss, but if I don't add the GO I get the error that the column Im adding value to don't exist. o_O Example:
2
1561
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 I need to do now is change the table name in my query so the report runs against a new table/query. Is there a way for me to programmatically change the sql string of a query or perhaps is it possible to have the table name act as a variable to be...
5
1969
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 Compare Database Option Explicit Declare Function WNetGetUser Lib "mpr.dll" _
0
9454
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10264
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10106
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9914
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6716
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5355
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4009
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3610
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2851
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.