DEV Community

CodetoLive blog
CodetoLive blog

Posted on • Originally published at codetolive.in on

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

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

Enter fullscreen mode Exit fullscreen mode

Top comments (0)