Temp Table and Real Table Usage Patern Question

  • I am reviewing some stored procedures coded by the previous DBA.

    I see the following construct repeated though out the code:

    select * into pqchildren from #pqchildren

    drop table pqchildren

    Can someone explain to me why this coding pattern would useful?

  • the only reason i can think he would have done that is because when he does the "into" statment he is actually creating a real table w/ that name and those records from the select. Normally you would do that if you have other stored procedures or processes that will reference this newly created table.

  • so when he's running

    select * into pqchildren from #pqchildren

    then whatever db you are in you will see a new table called pqchildren

    the below will obviously drop the newly created table

    drop table pqchildren

  • The funny part of the code is that the two statements always follow one another with no other code in between.

    I was thinking that somehow the code was throwing data into memory, but that did not really make sense either.

  • sounds like bad code to me.......i would hesitate changing it late friday unless ur glutton for punishment.

    I grew up w/ a mike french. ur not from florida are u?

  • michael.french 172 (1/29/2010)


    Can someone explain to me why this coding pattern would useful?

    That looks like an ugly workaround for something the previous guy didn't know how to do properly.

    Check for a database trigger fired on create table events - there might be some sort of dumb auditing scheme in place...?

Viewing 6 posts - 1 through 5 (of 5 total)

You must be logged in to reply to this topic. Login to reply