SQL Server 2016 T-SQL updates

Looking through the T-SQL updates for SQL Server 2016 this one caught my eye DROP IF EXISTS.
So when you normally drop a table for example you use IF OBJECT_ID:
IF OBJECT_ID(N'dbo.MyTable') IS NOT NULL

DROP TABLE dbo.MyTable
now you can use:
DROP TABLE IF EXISTS dbo.MyTable
It’s not just for tables you can use it for object such as:
AGGREGATE
ASSEMBLY
DATABASE
DEFAULT
FUNCTION
INDEX
PROCEDURE
ROLE
RULE
SCHEMA
SECURITY
SEQUENCE
SYNONYM
TABLE
TRIGGER
TYPE
USER
VIEW
Not in the SQL Server Blog Post that announced this update but you can also drop COLUMN and CONSTRAINT

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s