Sql Drop Temp Table If Exists

 1,825 Total Views,  5 views today

Sql Drop Temp Table If Exists:
Drop a temporary table if it is already created or exists. Then you can create same temporary table if you want.
This is require when you’ve created a temp table in your script, and every time you execute the script you have to drop the temp table manually.

USE YourDatabaseName
IF OBJECT_ID(‘tempdb..#YourTempTableName’) IS NOT NULL
DROP TABLE #YourTempTableName;

USE Banking
IF OBJECT_ID(‘tempdb..#TempAccounts’) IS NOT NULL
DROP TABLE #TempAccounts;

Also See: Drop Table If Exists Sql Server

Leave a Reply

Your email address will not be published. Required fields are marked *