SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


@Table vs #Table


@Table vs #Table

Author
Message
gerald.green
gerald.green
SSC Rookie
SSC Rookie (35 reputation)SSC Rookie (35 reputation)SSC Rookie (35 reputation)SSC Rookie (35 reputation)SSC Rookie (35 reputation)SSC Rookie (35 reputation)SSC Rookie (35 reputation)SSC Rookie (35 reputation)

Group: General Forum Members
Points: 35 Visits: 21
I'll start by saying that I am a C# developer, not a DBA. When it comes to performance tweaks and making the Procs I write run the fastest they can, I trust the DBAs.

My last job, I was told by more that one DBA that table variables run in RAM and do not access the hard drive. I worked with the DBAs for over six years and came to trust & value what they told me. I used Table Variables when ever possible and didn't use Temp Tables.

While reworking a (messy) stored procedure at my current job the DBA told me "That is a common misconception. Table Variables and Temp Tables both access TempDB. Therefore, IO hard drive access."

Which DBA is correct?
Lynn Pettis
Lynn Pettis
SSC Guru
SSC Guru (95K reputation)SSC Guru (95K reputation)SSC Guru (95K reputation)SSC Guru (95K reputation)SSC Guru (95K reputation)SSC Guru (95K reputation)SSC Guru (95K reputation)SSC Guru (95K reputation)

Group: General Forum Members
Points: 95014 Visits: 38963
The one you work with now. However, it is possible that one or both will access tempdb or that one or both will reside completely in memory. It all depends on the amount of data and the query.

The biggest thing to remember is the table variables do not have statistics and will be treated by the optimizer as if they have one row, regardless of the actual number of rows they have. I have heard differently at times, but my experience seems to hold this to be true. Best to test for yourself.

Cool
Lynn Pettis

For better assistance in answering your questions, click here
For tips to get better help with Performance Problems, click here
For Running Totals and its variations, click here or when working with partitioned tables
For more about Tally Tables, click here
For more about Cross Tabs and Pivots, click here and here
Managing Transaction Logs

SQL Musings from the Desert Fountain Valley SQL (My Mirror Blog)
Mark Cowne
Mark Cowne
SSCertifiable
SSCertifiable (6.4K reputation)SSCertifiable (6.4K reputation)SSCertifiable (6.4K reputation)SSCertifiable (6.4K reputation)SSCertifiable (6.4K reputation)SSCertifiable (6.4K reputation)SSCertifiable (6.4K reputation)SSCertifiable (6.4K reputation)

Group: General Forum Members
Points: 6445 Visits: 25549
There's an excellent article here

____________________________________________________

Deja View - The strange feeling that somewhere, sometime you've optimised this query before

How to get the best help on a forum

http://www.sqlservercentral.com/articles/Best+Practices/61537




GilaMonster
GilaMonster
SSC Guru
SSC Guru (224K reputation)SSC Guru (224K reputation)SSC Guru (224K reputation)SSC Guru (224K reputation)SSC Guru (224K reputation)SSC Guru (224K reputation)SSC Guru (224K reputation)SSC Guru (224K reputation)

Group: General Forum Members
Points: 224745 Visits: 46321
http://sqlinthewild.co.za/index.php/2010/10/12/a-trio-of-table-variables/

The 'table variables are memory only' is an all-too-common misconception. Both temp tables and table variables are allocated space in TempDB and added to the tempDB system tables. They may however not actually be on disk, SQL will try to keep them both in memory as much as possible because it's very likely that those pages will be needed again shortly.

Gail Shaw
Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

We walk in the dark places no others will enter
We stand on the bridge and no one may pass


Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search