June 16, 2010 at 12:17 am
Hello,
in a sql-statement, i declare a table in the currently used database called "geo" ("DECLARE @tablename TABLE .....").
I know that its stored only till the connection is closed.
But can somebody tell me where my temporary declared table is stored physically? (ram or harddisk?)
Best Regards,
float
June 16, 2010 at 12:26 am
Hi,
You have created a Table variable which is always tempary in nature all TEmp tables and variables stay in Tempdb database and all are sessional in nature. i mean to say all these temp variables will automatically flushed out once your session is closed.
temprary variables like in your case pyhsically remains in RAM.
Temp table or Hash(#) tables are kept in the data file of a Tempdb database till the session is alive.
Too many Temp tables might increase you Tempdb size as well so set an adequate size for tempdb database.
I hope you got your answer.
Regards,
Sachin Sharma
June 16, 2010 at 1:14 am
Thanks 🙂
June 16, 2010 at 1:16 am
sachnam (6/16/2010)
temprary variables like in your case pyhsically remains in RAM.
Myth.
http://scarydba.wordpress.com/2009/10/13/table-variables-are-only-in-memory-fact-or-myth/
June 16, 2010 at 1:24 am
"Other than that, both will reside completely in memory or will swap out to the disk through tempdb, depending on their size."
So, if the size of these temp table is small, it will be stored in memory.
If there is enough memory free, it will definitly be stored in memory.
June 16, 2010 at 2:52 am
sachnam (6/16/2010)
temprary variables like in your case pyhsically remains in RAM.Temp table or Hash(#) tables are kept in the data file of a Tempdb database till the session is alive.
Common myth, totally and completely wrong.
Both temp tables and table variables are allocated space in TempDB. They are both preferentially kept in memory and only spilt to disk in case of memory pressure. It is completely wrong to say that table variables are in memory only and temp tables only on disk. They are treated the same with regards to their storage.
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
June 16, 2010 at 5:57 am
GilaMonster (6/16/2010)
Both temp tables and table variables are allocated space in TempDB. They are both preferentially kept in memory and only spilt to disk in case of memory pressure. It is completely wrong to say that table variables are in memory only and temp tables only on disk. They are treated the same with regards to their storage.
And this physical presence in tempdb can be proved. See this article[/url] which shows how to demonstrate this.
Wayne
Microsoft Certified Master: SQL Server 2008
Author - SQL Server T-SQL Recipes
June 18, 2010 at 1:46 am
GilaMonster (6/16/2010)
sachnam (6/16/2010)
temprary variables like in your case pyhsically remains in RAM.Temp table or Hash(#) tables are kept in the data file of a Tempdb database till the session is alive.
Common myth, totally and completely wrong.
Interestingly, while working through Microsoft's training book for 70-433 I came across this, in answer to one of the questions:
"You can eliminate all the intermediate temporary tables by using derived tables, which can take advantages of the memory available on the machine instead of requiring physical reads and writes to disk."
From SSC I've known the truth of it for a while, but when MS's own material implies otherwise it's no wonder so many think that way.
BrainDonor.
June 18, 2010 at 2:01 am
Derived tables are not temp table (either # or @)
What, i think, that question is doing is drawing a distinction between...
create table #table
(Cola int)
insert into #table
Select cola from tablea
select * from tableb
join #tablea
on tableb.col = tablea.col
and
select * from tableb
join (Select col from tablea) as derived
on Derived.col = tableb.col
June 18, 2010 at 2:14 am
I see what you are saying, IMO, for the sake of brevity the question is fine.
It would be a much larger book if every question had a footnote for all the "it depends" option 😀
June 18, 2010 at 2:34 am
BrainDonor (6/18/2010)
Interestingly, while working through Microsoft's training book for 70-433 I came across this, in answer to one of the questions:"You can eliminate all the intermediate temporary tables by using derived tables, which can take advantages of the memory available on the machine instead of requiring physical reads and writes to disk."
From SSC I've known the truth of it for a while, but when MS's own material implies otherwise it's no wonder so many think that way.
Derived tables aren't tables at all.
The quality of the exam guide books is occasionally on the questionable side...
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
Viewing 13 posts - 1 through 12 (of 12 total)
You must be logged in to reply to this topic. Login to reply