Enhanced DML and DDL statements
In this section, you will explore enhancements in Data Manipulation Language (DML) and Data Definition Language (DDL) that are not part of new features or improved features from previous SQL Server versions.
The section starts with a small syntax extension that you will use often in the code examples in this book.
The conditional DROP statement (DROP IF EXISTS)
With a conditional DROP
statement, you can avoid getting an exception if the object you want to drop does not exist. If, for instance, the T1
table has already been removed or it was not created at all, the following statement will fail:
DROP TABLE dbo.T1;
Here is the error message:
Msg 3701, Level 11, State 5, Line 5 Cannot drop the table 'dbo.T1', because it does not exist or you do not have permission.
SQL Server 2016 introduces the conditional DROP
statement for most of the database objects. The conditional DROP
statement is a DROP
statement extended with the IF EXISTS
part. Repeat the preceding...