Quantcast
Channel: Scripts – SqlHints.com
Viewing all articles
Browse latest Browse all 28

How to check if Temp table exists in Sql Server?

$
0
0

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


Viewing all articles
Browse latest Browse all 28

Trending Articles