Dropping #TempTable

  • I've seen this posted, but I cannot remember how to do it. 

     

    If I have a table called AP, I can drop it this way: 

    IF EXISTS( SELECT * FROM dbo.sysobjects WHERE id = object_id(N'[dbo].[AP]')

     AND OBJECTPROPERTY(id, N'IsUserTable') = 1)

    DROP TABLE [dbo].[AP]

    GO

     

    If I am running a script multiple times, how can I do the same thing for a #TempTable?  I know I need to reference TempDB, but for the life of me, I cannot remember, (or figure out) how to do this... 

    TIA 

    Farrell

    I wasn't born stupid - I had to study.

  • if not object_id ('temp..TempTable') is null

    begin

     drop table #TempTable

    end


    * Noel

  • BTW you should actually drop the temp table at the end of the proc... why should this be a problem for you??

    Also note that each user can have its own temp table so that can't be a problem either (unless the table is global).

  • The problem may be a context issue. You may be runing a batch and you want to make sure that it works reapeatedly then is an easy way to do it

     


    * Noel

  • Still guessing without the code??? I'm gonna have to have a little talk with your mother, or boss about this .

  • At this point who cares?

    BTW: do you have a boss? ( or a job for that matter ? ) 

     


    * Noel

  • I'll plead the 5th on this one.

  • I know.  This is for one of those situations in which you are not sure of the data and need to test various scenarios, so I may keep #TempTable around for a while and select various things from it...  It's basically for a testing script. 

    And, (on occassion) I may not shut down at the end of the day if I have not figured out the problem and I want that #TempTable data left around... 

    Thanks for the replies....  brain lock.   

     

    btw: my mother would be happy to tell you all about me ("50 hours of labor and this is how you turned out, boy?"  ), but as for my boss - that is hush, hush.... 

     

    Where the heck if Frank?  I haven't seen a post from him in what seems ages.  Is his newborn keeping him too busy? 

    I wasn't born stupid - I had to study.

  • Chicken ?


    * Noel

  • OMG!  That post made me an addict.  More than coincidence? 

    I wasn't born stupid - I had to study.

  • Heheeheeee.  Noel called you a chicken.  heheeee 

    I wasn't born stupid - I had to study.

  • Yup, and I don't care .

  • Where's sushila when I need her?  She's much better at giving you a hard time than I am....   

    (btw: do you not "care" or do you not "case"?) 

    I wasn't born stupid - I had to study.

  • Remi, c'mon what is the mistery ?


    * Noel

  • Sushila would have spotted that typo right away. I was saying "I don't care" and "I'm not making a case out of this" in the same sentence . Now you see how fast I think .

Viewing 15 posts - 1 through 15 (of 24 total)

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