Original: SQL Server 2016 new feature: DROP IF EXISTS
??
When we write T-SQL to delete an object (table, stored procedure, etc.), it is customary to use the IF statement to determine whether the object exists and then drop it, for example:
Old version:
IF object_id (' dbo. Person ', ' U ') was not a nulldrop table personif EXISTS (SELECT * from sys.objects where name = "person") DROP table person
SQL Server 2016 simplifies this operation by following a simple SQL sentence:
New version (SQL Server 2016):
DROP TABLE IF EXISTS person
The syntax for DROP IF exists is as follows:
drop object_type if Span lang= "en-US" style= "font-family: ' New song body '; color: #000000; background: #FFFFFF; font-size:9.5pt;" xml:lang= "en-US" > EXISTS object_name
Can be used for drop object_type, such as tables, Database, Function, Trigger, Stored Procedure, Column, User, type, View, Schema, can be applied, such as:
ALTER TABLE persondrop COLUMN If EXISTS NAME
SQL Server 2016 new features: DROP IF EXISTS