using Object_id() function with #tables

前端 未结 4 1570
醉话见心
醉话见心 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条回答
  •  旧巷少年郎
    2020-12-11 01:16

    When OBJECT_ID is called, for Temporary table/Hash table TEMPDB it must be specified unless it is already working database.

    I check in SQL2008 and verify below.

    USE SampleDB
    create table #tt1 (dummy int)
    select OBJECT_ID('SampleDB..#tt1')  -- returns NULL
    select OBJECT_ID('tempdb..#tt1')   -- returns ID
    

提交回复
热议问题