Unix Technical Forum

The age old argument of Temp table vs Table variable

This is a discussion on The age old argument of Temp table vs Table variable within the SQL Server forums, part of the Microsoft SQL Server category; --> Hi All, Hope someone can help me... Im trying to highlight the advantages of using table variables as apposed ...


Go Back   Unix Technical Forum > Database Server Software > Microsoft SQL Server > SQL Server

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 03-01-2008, 12:09 PM
Burbletrack
 
Posts: n/a
Default 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?

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 03-01-2008, 12:09 PM
Helmut Woess
 
Posts: n/a
Default Re: The age old argument of Temp table vs Table variable

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
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 03-01-2008, 12:10 PM
Erland Sommarskog
 
Posts: n/a
Default Re: The age old argument of Temp table vs Table variable

Burbletrack (ernst.geyser@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, esquel@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
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 05:10 AM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0
www.UnixAdminTalk.com