Check if a temporary table exists and delete if it exists before creating a temporary table

前端 未结 15 801
忘掉有多难
忘掉有多难 2020-11-29 14:13

I am using the following code to check if the temporary table exists and drop the table if it exists before creating again. It works fine as long as I don\'t change the colu

15条回答
  •  一个人的身影
    2020-11-29 14:55

    This worked for me: social.msdn.microsoft.com/Forums/en/transactsql/thread/02c6da90-954d-487d-a823-e24b891ec1b0?prof=required

    if exists (
        select  * from tempdb.dbo.sysobjects o
        where o.xtype in ('U') 
    
       and o.id = object_id(N'tempdb..#tempTable')
    )
    DROP TABLE #tempTable;
    

提交回复
热议问题