drop table if exists sql server code example

Example 1: sql server drop temp table if exists

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

Example 2: sql drop table if exists

DROP TABLE IF EXISTS dbo.Customers

Example 3: drop table if exists

DROP TABLE IF EXISTS dbo.Scores

Example 4: sql server drop table if exists

IF OBJECT_ID('dbo.Scores', 'U') IS NOT NULL DROP TABLE dbo.Scores;

Example 5: sql drop table if exists

IF OBJECT_ID('dbo.Scores', 'U') IS NOT NULL 
  DROP TABLE dbo.Scores;

Example 6: sql server drop table if exists

-- Classic table
IF OBJECT_ID('my_schema.my_table', 'U') IS NOT NULL DROP TABLE my_schema.my_table; 
-- Temporary table
IF OBJECT_ID('tempdb.my_schema.#my_table') IS NOT NULL DROP TABLE #my_table;

Tags:

Sql Example