SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


What is the behavior of aliased SELECT statements?


What is the behavior of aliased SELECT statements?

Author
Message
Ronald Kutsch
Ronald Kutsch
SSC Veteran
SSC Veteran (202 reputation)SSC Veteran (202 reputation)SSC Veteran (202 reputation)SSC Veteran (202 reputation)SSC Veteran (202 reputation)SSC Veteran (202 reputation)SSC Veteran (202 reputation)SSC Veteran (202 reputation)

Group: General Forum Members
Points: 202 Visits: 77
I have had success in avoiding the explicit creation of temp tables to store intermediate results by aliasing a SELECT statement and using it as a table in a DML statement. My question is, how does SQL Server handle this behavior internally? Is this aliased statement stored in the buffer cache, or is it stored in tempdb as some kind of internal object, or as a temp table, or is there another behavior that I am not thinking of? Thanks in advance!
GSquared
GSquared
SSC-Insane
SSC-Insane (23K reputation)SSC-Insane (23K reputation)SSC-Insane (23K reputation)SSC-Insane (23K reputation)SSC-Insane (23K reputation)SSC-Insane (23K reputation)SSC-Insane (23K reputation)SSC-Insane (23K reputation)

Group: General Forum Members
Points: 23759 Visits: 9730
If you look at the execution plan, it will tell you what it's doing with it. You can also check "set statistics io on" and see data movement in it (if it does materialize it into tempdb) that way.

What it does depends on a few things. If there's a lot of data, it will usually dump it into a worktable, which is essentially an implicit temp table. If it's only a small amount of data, it will just hold it in memory. That's WAY oversimplified, but it's essentially the 100-mile overview.

- Gus "GSquared", RSVP, OODA, MAP, NMVP, FAQ, SAT, SQL, DNA, RNA, UOI, IOU, AM, PM, AD, BC, BCE, USA, UN, CF, ROFL, LOL, ETC
Property of The Thread

"Nobody knows the age of the human race, but everyone agrees it's old enough to know better." - Anon
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search