table variables are not written to tempDB.
I just think that it's difficult to use these because you can't persist
a connection in ADO.net
in 80% of the cases; using insert into @table would be faster-- becasue
you're using it for writes and reads.
using it for writes is always faster for table variables.. I think..
because you don't have logging for example.
I think that if you had 100 users doing this; table variables would be
a better choice.. but I think that they can use up a lot more memory.
I personally dislike table-valued functions and all that crap.. I just
don't trust them.
but yeah; if you were running 100 inserts and then a read; I believe a
table variable would almost always be faster
for other situations-- maybe more real world type solutions; I think
that there are a lot of reasons to avoid table variables.. like
overhead and latency.. I just think that if you've got a properly
configured tempdb (seperate array; raid 0?) then you'll have adequate
performance either way.. and I just have a gumption that table
variables are more reliable-- since we've been using them for 10+ years
and table variables aren't that old by a long shot
I dont think that you can pin table variables.. and i think that table
variables are less memory efficient than temp tables... and I think
that table variables are less capable of disk caching and sql server
memory caching than table variables
I think that the ability to write an index on a temp table is not
something that you should overlook.. an index on a small table might
increase performance dramatically depending on the type of operation
that you're doing
there's a good article at sql mag about temp tables vs table variables
I think that they were maybe a 7 on a scale of 1 to 10 about tmp tables
(1) to table variables (10).
I think that I'm move like a 6 on a scale of 1 to 10.
If I could push the results of a qry into a table variable using a
Select Into From (maketable query) then I might like table variables a
lot more.
-Aaron
[quoted text, click to view] jebuskrust@gmail.com wrote:
> 1 - Next question: Are table variables stored in memory or are they
> stored in tempdb like #temp_tables?
>
> Which is faster to query..
>
> Say I Populated data between 1-100 and stored it into a @table variable
>
> Like so:
>
> insert into @table
> 1
> 2
> 3
> 4
> ... 100
>
> And ran select * from @table
> Or
>
> Say I Populated data between 1-100 and stored in a #temp table
> Like so
>
> insert into #temp
> 1
> 2
> 3
> 4
> ... 100
> select * from #table
> drop table #table
>
> Comments or suggestions are appreciated..
>
>
>
>
> Martin wrote:
> > Would this also be the case for SQL 2005 CTEs? Do they essentially use
> > table variables internally?
> >
> > I changed some code on my laptop to use a CTE and it ran much quicker.
> > However on the mutli-proc server, it actually ran slower than the temp
> > table version.
> >
> > Martin
> >
> >
> > aaron.kempf@gmail.com wrote:
> > > depends on SMP count and other things.
> > >
> > > I'd recomend temp tables in most situations; because @table variables
> > > are limited to a single processor.. and processor count is going UP
> > > faster now than any other time in history-- next year the common db
> > > server might be a dual socket quad core.. so the penalty for @table
> > > variables goes up over time
> > >
> > > (because of high cpu/core counts)
> > >
> > > -Aaron
> > >
> > >
> > >
> > > jebuskrust@gmail.com wrote:
> > > > Just wondering if using @table variables can be more optimal for
> > > > performance or if one should use #tmp tables instead ?
> > > >
> > > > Thanks
table variables are not written to tempDB.
I just think that it's difficult to use these because you can't persist
a connection in ADO.net
in 80% of the cases; using insert into @table would be faster-- becasue
you're using it for writes and reads.
using it for writes is always faster for table variables.. I think..
because you don't have logging for example.
I think that if you had 100 users doing this; table variables would be
a better choice.. but I think that they can use up a lot more memory.
I personally dislike table-valued functions and all that crap.. I just
don't trust them.
but yeah; if you were running 100 inserts and then a read; I believe a
table variable would almost always be faster
for other situations-- maybe more real world type solutions; I think
that there are a lot of reasons to avoid table variables.. like
overhead and latency.. I just think that if you've got a properly
configured tempdb (seperate array; raid 0?) then you'll have adequate
performance either way.. and I just have a gumption that table
variables are more reliable-- since we've been using them for 10+ years
and table variables aren't that old by a long shot
I dont think that you can pin table variables.. and i think that table
variables are less memory efficient than temp tables... and I think
that table variables are less capable of disk caching and sql server
memory caching than table variables
I think that the ability to write an index on a temp table is not
something that you should overlook.. an index on a small table might
increase performance dramatically depending on the type of operation
that you're doing
there's a good article at sql mag about temp tables vs table variables
I think that they were maybe a 7 on a scale of 1 to 10 about tmp tables
(1) to table variables (10).
I think that I'm move like a 6 on a scale of 1 to 10.
If I could push the results of a qry into a table variable using a
Select Into From (maketable query) then I might like table variables a
lot more.
-Aaron
[quoted text, click to view] jebuskrust@gmail.com wrote:
> 1 - Next question: Are table variables stored in memory or are they
> stored in tempdb like #temp_tables?
>
> Which is faster to query..
>
> Say I Populated data between 1-100 and stored it into a @table variable
>
> Like so:
>
> insert into @table
> 1
> 2
> 3
> 4
> ... 100
>
> And ran select * from @table
> Or
>
> Say I Populated data between 1-100 and stored in a #temp table
> Like so
>
> insert into #temp
> 1
> 2
> 3
> 4
> ... 100
> select * from #table
> drop table #table
>
> Comments or suggestions are appreciated..
>
>
>
>
> Martin wrote:
> > Would this also be the case for SQL 2005 CTEs? Do they essentially use
> > table variables internally?
> >
> > I changed some code on my laptop to use a CTE and it ran much quicker.
> > However on the mutli-proc server, it actually ran slower than the temp
> > table version.
> >
> > Martin
> >
> >
> > aaron.kempf@gmail.com wrote:
> > > depends on SMP count and other things.
> > >
> > > I'd recomend temp tables in most situations; because @table variables
> > > are limited to a single processor.. and processor count is going UP
> > > faster now than any other time in history-- next year the common db
> > > server might be a dual socket quad core.. so the penalty for @table
> > > variables goes up over time
> > >
> > > (because of high cpu/core counts)
> > >
> > > -Aaron
> > >
> > >
> > >
> > > jebuskrust@gmail.com wrote:
> > > > Just wondering if using @table variables can be more optimal for
> > > > performance or if one should use #tmp tables instead ?
> > > >
> > > > Thanks
Don't see what you're looking for? Try a search.