MyTechMantra.com
Connect With MyTechMantra.com

Like Us on Facebook    Follow Us on Twitter     Subscribe to our Feeds     Subscribe to NewsLetter


















Trending SQL Server Tips






SQL Server 2016: DROP IF EXISTS T-SQL Enhancement

Read Comments   |   Related Topic: TSQL Enhancements SQL Server 2016 > Next Topic: ALTER TABLE WITH (ONLINE = ON | OFF)


Click here to read about new T-SQL enhancements in SQL Server 2016 from the beginning...

DROP IF EXISTS T-SQL Enhancement in SQL Server 2016

SQL Server 2016 introduces a new DROP IF EXISTS statement to DROP objects such as tables, columns, indexes, stored procedures, schemas, triggers and user-defined functions. DROP IF EXISTS statement can be used to check whether the object exists before it is dropped or removed from the database.

Prior to SQL Server 2016 you would write the T-SQL script similar to one below to check whether the object existed before it could be dropped from the database.

Use <DATABASENAME>
GO

IF EXISTS (SELECT 1 FROM sys.objects WHERE object_id = OBJECT_ID(N'[SchemaName].[TableName]') 
AND [type] IN (N'U')) 

DROP TABLE [SchemaName].[TableName]
GO

Related Tips

ALTER TABLE WITH (ONLINE = ON | OFF) T-SQL Enhancement in SQL Server 2016
MAXDOP for DBCC CHECKDB, DBCC CHECKTABLE and DBCC CHECKFILEGROUP
ALTER DATABASE SET AUTOGROW_SINGLE_FILE T-SQL Enhancement in SQL Server 2016
COMPRESS and DECOMPRESS T-SQL Enhancement in SQL Server 2016
STRING_SPLIT and STRING_ESCAPE T-SQL Enhancement in SQL Server 2016

Thank you for taking your time to read this article. Let's be Connected....

Sign-up for Our Newsletter to Get Free SQL Server Tips and News to Build your Career

Like MyTechMantra on Facebook to get updates on What's Happening in SQL Server

Example DROP IF EXISTS in SQL Server 2016

Starting SQL Server 2016, you could achieve the same functionality by executing the below simplified T-SQL script.

Use <DATABASENAME>
GO

DROP TABLE IF EXISTS [SchemaName].[TableName]
GO

DROP PROCEDURE IF EXISTS [SchemaName].[ProcedureName]
GO

Click the Next Page button to continue reading about New T-SQL enhancements in SQL Server 2016 and click on the Previous Page button to revise the previouly read topic.

Previous Page.. Next Page..




Learn More...





Last Updated On: May 10, 2016



Share this Article



Receive Free SQL Server Tips and Keep Learning
Get Free SQL Server Tips




Please leave your Valuable Comment or Let us know how this article helped you: