Home Forums SQL Server 2005 Administering Which one is better select * into # temp from tableA Vs create #temp table insert into... RE: Which one is better select * into # temp from tableA Vs create #temp table insert into...

  • Craig Farrell (6/22/2011)


    Yeeps, sorry Orlando, I fear you may have taken me the wrong way. I meant to add to your commentary, not abuse it. Apologies.

    No way Craig. I re-read my post and it's me who got defensive, sorry about that.

    Your experiences are very valuable to hear because I have seen it be better both ways. It is surprising however that SELECT...INTO may be preferred in most cases. HEAP to HEAP I could see SELECT...INTO being faster than CREATE TABLE followed by INSERT...SELECT in most cases, it's when there is a CI involved where I think it gets more interesting. Intuition and what I know of internals (admittedly not a lot) leads me to think that having a CI in place ahead of time and asking for an ordered insert from the INSERT...SELECT would be preferred in most cases because I am not writing a heap just to tear it down and rebuild it as a clustered table...I may do some testing too.

    I like the script you provided Schadenfreude-Mei. It solves the issue Ken raised by remaining dynamic but it also allows you to create a CI ahead of time. Very creative. Thanks for sharing.

    There are no special teachers of virtue, because virtue is taught by the whole community.
    --Plato