Check if a temporary table exists and delete

For anything related to MS SQL Server.
Post Reply
admin
Site Admin
Posts: 1
Joined: 26 Jul 2025 13:00
Location: UK
Contact:

Check if a temporary table exists and delete

Post by admin »

To check if a MS SQL Server temporary table exists and delete:

Code: Select all

DROP TABLE IF EXISTS #MyTempTableNamesults
On older versions of SQL Server (pre 2016) you can use:

Code: Select all

IF OBJECT_ID('tempdb..#MyTempTableName') IS NOT NULL
    DROP TABLE #MyTempTableName
Post Reply