SQL Server 2016 new features: DROP IF EXISTS

Source: Internet
Author: User

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):


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:


SQL Server 2016 new features: DROP IF EXISTS

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.