SQL Server 2016 New Feature for Drop Object if Exist.(DROP IF EXISTS)

Are you use to write following conditional DROP statements:

IF OBJECT_ID('dbo.Product', 'U') IS NOT NULL
 DROP TABLE dbo.Product;

IF EXISTS (SELECT * FROM sys.triggers WHERE name = 'trProductInsert')

 DROP TRIGGER trProductInsert


Now SQL Server 2016 come with new syntax/Keyword for this, So If you are using SQL Server 2016 then take advantage of this feature, you might try new DROP IF EXISTS (a.k.a. DIE :) ) statements in SQL Server 2016.
From SQL Server 2016 CTP3 you can use new DIE  statements instead of big IF wrappers, e.g.:

DROP TABLE IF EXISTS dbo.Product

DROP TRIGGER IF EXISTS trProductInsert

*Advantage of using this is that If the object does not exists, DIE will not fail and execution will continue.

Comments

Contact Form

Send