using Object_id() function with #tables

前端 未结 4 1573
醉话见心
醉话见心 2020-12-11 00:51

I want to ensure if a temporary table exists in my database or not.

I tried to use OBJECT_ID() function but it seems that I can\'t use it with temporary

4条回答
  •  旧时难觅i
    2020-12-11 01:02

    From SQL Server Codebook

    How do you check if a temp table exists?
    You can use IF OBJECT_ID('tempdb..#temp') IS NOT NULL
    

    SQL Script

    --Check if it exists
    IF OBJECT_ID('tempdb..#temp') IS NOT NULL
    BEGIN
    PRINT '#temp exists!'
    END
    ELSE
    BEGIN
    PRINT '#temp does not exist!'
    END
    

提交回复
热议问题