How to Check for and Delete Temp Local Table?

  • if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[LV_Group]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)

    drop table [dbo].[LV_Group]

    The above syntax checks and deletes a regular table. How do I write one that checks for a local temp table? For example, how do I check for the existence of a local temp table "#tbl_temp" and delete it? Thanks.

  • if exists (select * from tempdb.dbo.sysobjects where id = OBJECT_ID('tempdb..#tbl_temp'))

    drop table [dbo].[#tbl_temp]

  • or just

    Object_ID('TempDb..#Temp') is not NULL

    (which I found in a previous posting but I cannot find now to attribute it, sorry)

Viewing 3 posts - 1 through 2 (of 2 total)

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