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 (1)

Collapse
 
brunotdantas_br profile image
Bruno Dantas • Edited

Another way is

DROP TABLE IF EXISTS #YOUR_TEMP_TABLE

Postmark Image

Speedy emails, satisfied customers

Are delayed transactional emails costing you user satisfaction? Postmark delivers your emails almost instantly, keeping your customers happy and connected.

Sign up