Log in
::
Register
::
Not logged in
Home
Tags
Articles
Editorials
Stairways
Forums
Scripts
Videos
Blogs
QotD
Books
Ask SSC
SQL Jobs
Training
Authors
About us
Contact us
Newsletters
Write for us
Recent Posts
Recent Posts
Popular Topics
Popular Topics
Home
Search
Members
Calendar
Who's On
Home
»
SQL Server 7,2000
»
T-SQL
»
@Table vs #Table
@Table vs #Table
Rate Topic
Display Mode
Topic Options
Author
Message
gerald.green
gerald.green
Posted Thursday, March 21, 2013 9:45 AM
SSC Rookie
Group: General Forum Members
Last Login: Monday, April 01, 2013 12:37 PM
Points: 29,
Visits: 17
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?
Post #1433875
Lynn Pettis
Lynn Pettis
Posted Thursday, March 21, 2013 9:51 AM
SSC-Insane
Group: General Forum Members
Last Login: Today @ 2:45 AM
Points: 21,630,
Visits: 27,485
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.
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)
Post #1433881
Mark-101232
Mark-101232
Posted Thursday, March 21, 2013 10:42 AM
SSCommitted
Group: General Forum Members
Last Login: Yesterday @ 9:53 AM
Points: 1,501,
Visits: 18,208
There's an excellent article
here
____________________________________________________
How to get the best help on a forum
http://www.sqlservercentral.com/articles/Best+Practices/61537
Never approach a goat from the front, a horse from the rear, or a fool from any direction.
Post #1433906
GilaMonster
GilaMonster
Posted Thursday, March 21, 2013 11:42 AM
SSC-Dedicated
Group: General Forum Members
Last Login: Today @ 4:30 AM
Points: 37,742,
Visits: 30,021
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 2008, MVP
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
Post #1433938
« Prev Topic
|
Next Topic »
Permissions
You
cannot
post new topics.
You
cannot
post topic replies.
You
cannot
post new polls.
You
cannot
post replies to polls.
You
cannot
edit your own topics.
You
cannot
delete your own topics.
You
cannot
edit other topics.
You
cannot
delete other topics.
You
cannot
edit your own posts.
You
cannot
edit other posts.
You
cannot
delete your own posts.
You
cannot
delete other posts.
You
cannot
post events.
You
cannot
edit your own events.
You
cannot
edit other events.
You
cannot
delete your own events.
You
cannot
delete other events.
You
cannot
send private messages.
You
cannot
send emails.
You
may
read topics.
You
cannot
rate topics.
You
cannot
vote within polls.
You
cannot
upload attachments.
You
may
download attachments.
You
cannot
post HTML code.
You
cannot
edit HTML code.
You
cannot
post IFCode.
You
cannot
post JavaScript.
You
cannot
post EmotIcons.
You
cannot
post or upload images.
Copyright © 2002-2013 Simple Talk Publishing. All Rights Reserved.
Privacy Policy.
Terms of Use.
Report Abuse.