Wednesday, March 17, 2021

Drop Temp Tables if exists in Temp DB using single line Code in MS SQL Server

Drop the temp table if exists in tempdb and create table:

IF OBJECT_ID('tempdb..#Results') IS NOT NULL

    DROP TABLE #Results

CREATE TABLE #Results

(

    Company                CHAR(3),

    StepId                TINYINT,

    FieldId                TINYINT,

)

Drop temp table using single line code :

DROP TABLE IF Exists #Results

Drop multiple temp tables using single line code :

DROP TABLE IF Exists #TempGPdataStep1,#TempGPdataStep2,#FinalGPDataStep1

No comments:

Post a Comment