sqlsql-server

using Object_id() function with #tables


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 tables.

How can I resolve this problem?


Solution

  • Use

    OBJECT_ID('tempdb..#foo')
    

    to get the id for a temporary table when running in the context of another database.