June 14, 2005 at 6:02 am
Hi,
Plse clarify my doubt...
when we create table variable where does the data stores?
I read some where that 'table variable does'nt occupy space in the tempdb as its temporary table counter part.Instead, the table data type uses the sql serevers memory to store data.'
Is it correct??
but I have monitored memory ,cpu and tempdb.
space of tempdb getting full and cpu utalization is high and nothing happens to memory??
Rgds
Binu John
June 14, 2005 at 6:19 am
It depends on the size of the table (and the memory avalaible). If the table is very small then it's gonna be in memory only, but at some point, it's gonna start writting on the disk.
June 14, 2005 at 6:35 am
Hi,
But this time I have made the data file size as I mb and run the query
set nocount on
declare @tmptable table
(
login char(50),
hstname char(50)
)
--select * from @tmptable
declare @i int
set @i=1
while @i<=1000000000
begin
insert into @tmptable values('binu','john')
set @i=@i+1
print @i
end
but after printing 11361 it shown the below error.
Could not allocate space for object '#78D4B6B2' in database 'TEMPDB' because the 'DEFAULT' filegroup is full.
From that it is clear that physical memory is not utilizing here.
Am I correct??
I have still enough memory that is not utilizing...
Rgds
Binu John
June 14, 2005 at 6:58 am
Obviously, nice thinking about this script.
June 14, 2005 at 10:06 pm
Dear Remi,
But can you clear the things for me.
I read this on 'Sql server 2000 for Experienced DBAs' writern by Brian Knight.
June 15, 2005 at 5:17 am
both #temp tables and table variables may be created in memory, likewise both may be created in tempdb.
[font="Comic Sans MS"]The GrumpyOldDBA[/font]
www.grumpyolddba.co.uk
http://sqlblogcasts.com/blogs/grumpyolddba/
June 15, 2005 at 5:20 am
but under what circumstances that will create in memory???
June 15, 2005 at 7:21 am
In order for it to be created, the table has to go in tempdb. The notion of created in memory comes from the fact that very small tables will probabely remain in heap for faster access while much bigger tables with require some disk io to be read.
June 15, 2005 at 10:53 pm
Then what is the advantage of having Table variable compared to temporary table??
June 16, 2005 at 8:04 am
Gives a second option. Less risk of sysobjects deadlocks. Can be faster under certain circumstances. But the fact is that you have to test in your environement to see which performs better with the expected data.
June 21, 2005 at 2:57 am
Even the table variables get stored in Temp db, if you wanna check try this script
Use tempdb
select count(*) from sysobjects where type = 'U' -- initial count
go
declare @myvar table (a int)
select count(*) from sysobjects where type = 'U' -- initial count + 1
go
select * from sysobjects where type = 'U' -- initial count again
go
Viewing 11 posts - 1 through 10 (of 10 total)
You must be logged in to reply to this topic. Login to reply