How to drop a table if it exists in SQL Server 2014 ?


This content was proof-read by Grammarly. You can Try Grammary for FREE

Assume that you want to write a SQL Query in SQL Server which checks if the table exists in database and want to drop it , you can use the OBJECT_ID function to determine the table existence by passing the table name and the ‘U’ as parameters.

How to drop a table if it exists in SQL Server 2014 ?

Use AdventureWorks2014
GO
IF OBJECT_ID('temp_abundantcode', 'U') IS NOT NULL 
  DROP TABLE temp_abundantcode; 
How to drop a table if it exists in SQL Server 2014 ?
%d bloggers like this: