To check Correctly if a Temporary Table Exists in SQL Server

In this blog, I will explain the procedure of checking correctly if a temporary table exists in the SQL Server or not.
 
 Step 1: Create a temp table.
 
 CREATE TABLE #TEMPTABLENAME
 (
 SNO INT
 )
 
 Step 2: Again create a temp table with the same name as in Step 1.
 
 CREATE TABLE #TEMPTABLENAME
 (
 SNO INT
 )
 
We will get an error same as the following.
 
 There is already an object named ‘#TEMPTABLENAME’ in the database.
 
 Step 3: To check whether a temp table exists or not.
 
 Given below is the code to check correctly if a temporary table exists in the SQL Server or not.
 
 IF OBJECT_ID('tempdb.. #TEMPTABLENAME) IS NOT NULL