How to check if a temporary table exists and delete it if it does before creating a temporary table?

less than 1 minute read

You can check if the previously created temporary table exists before creating the same table again in your stored procedure. Drop them if they exist.

Code:

// checks that the temporary table 'results' exists in the SQL tempdb.
IF OBJECT_ID('tempdb..#Results') IS NOT NULL DROP TABLE #Results
GO

Leave a comment