Sql Drop Temp Table If Exists

 886 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.

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

Example:
USE Banking
GO
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 *