How to check if a temp table exists and delete it in SQL Server

Useful Microsoft SQL Server code snippets.
Post Reply
Z12
Site Admin
Posts: 20
Joined: Thu Sep 30 2021, 11:47
Location: UK
Contact:

How to check if a temp table exists and delete it in SQL Server

Post by Z12 »

To check if a temp or hash table exists in SQL Server, and if it does then delete or drop it:

Code: Select all

IF OBJECT_ID('tempdb..#TempTableName') IS NOT NULL
    DROP TABLE #TempTableName
If you find Z12 Web Tools useful and would like to show your appreciation...
Why not Buy Me A Coffee to say: Thank You!


Post Reply