SQL Server 2016: DROP IF EXISTS T-SQL Enhancement
Related Topic: TSQL Enhancements SQL Server 2016>
Next Topic: ALTER TABLE WITH (ONLINE = ON | OFF)
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
• 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....
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.
- Different SQL Server Recovery Models Step by Step Tutorial with Examples
- How to Detect Database Corruption Issues in SQL Server Using Suspect_Pages Table of MSDB Database?
- SQL Server Best Practice: Why Auto Close Database Option Should Remain OFF
- How to Configure TempDB on Local Disk in SQL Server 2012 Failover Cluster to Improve Performance
- Steps to Connect to SQL Server When all System Administrators are Locked Out
- Limit SQL Server Error Log File Size in SQL Server 2012
- How to Convert Seconds to Minutes, Hours and Days in SQL Server
- Different Ways to Retrieve SQL Server Configuration Details
Last Updated On: May 10, 2016
Please leave your Valuable Comment or Let us know how this article helped you: