Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 does selecting a local variable hit the temp db ?

Author  Topic 

BitShift
Yak Posting Veteran

98 Posts

Posted - 2007-03-27 : 10:20:09
If you do something like:
declare @fred char(10)
select @fred = (select top 1 fieldhere from some table where ... order by ... desc)

Does this use the temp db ?

nr
SQLTeam MVY

12543 Posts

Posted - 2007-03-27 : 10:22:15
It might use tempdb to do the order by unless it can use an index for it.


==========================================
Cursors are useful if you don't know sql.
DTS can be used in a similar way.
Beer is not cold and it isn't fizzy.
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2007-03-27 : 10:23:02
Why not

select top 1 @fred = fieldhere from some table where ... order by ... desc


Peter Larsson
Helsingborg, Sweden
Go to Top of Page

X002548
Not Just a Number

15586 Posts

Posted - 2007-03-27 : 10:28:18
I think the answer is it would most likely use memory...table variables use memory



Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx

Add yourself!
http://www.frappr.com/sqlteam



Go to Top of Page

Lamprey
Master Smack Fu Yak Hacker

4614 Posts

Posted - 2007-03-27 : 15:10:25
quote:
Originally posted by X002548

I think the answer is it would most likely use memory...table variables use memory


If they are small enough to be held in memory. ;)
Go to Top of Page

dinakar
Master Smack Fu Yak Hacker

2507 Posts

Posted - 2007-03-27 : 16:10:24
AFAIK, TOP/ORDER BY definetely uses tempdb to do the sort.

************************
Life is short. Enjoy it.
************************
Go to Top of Page
   

- Advertisement -