How to check if Temp table exists in Sql Server?

This article shows how in Sql Server we can check the existence of Temporary Table.

To demonstrate this let us first create a Temporary Table with name #TempTable.

--Create Temporary Table
 CREATE TABLE #TempTable (Id INT)
 GO

Below script shows how we can check the existence of a Temporary Table #TempTable.

IF OBJECT_ID('TempDB.dbo.#TempTable') IS NOT NULL
BEGIN
  PRINT '#TempTable Temporary Table Exists'
END
GO

RESULT:
How to Check if Temporary Table exists in Sql Server

Note: As shown above to check the existence of a temporary table, we need give table name with three part naming convention i.e. DatabaseName.SchemaName.TemporaryTableName

[ALSO READ] :
How to check if a Database exists
How to check if a Table exists
How to check if a Stored Procedure exists in Sql Server
How to check if a View exists
How to check if a record exists in table

5 thoughts on “How to check if Temp table exists in Sql Server?

Leave a Reply

Your email address will not be published. Required fields are marked *