未加星标

The Complete Beginner’s Guide to DROP IF EXISTS in SQL SERVER

字体大小 | |
[数据库(mssql) 所属分类 数据库(mssql) | 发布者 店小二04 | 时间 2016 | 作者 红领巾 ] 0人收藏点击收藏

The Complete Beginner’s Guide to DROP IF EXISTS in SQL SERVER

In the Series of SQL SERVER 2016 journey , this is our new article. In this article, we are sharing a new cool feature which introduced in SQL SERVER 2016 which is DROP IF EXISTS (DIE) .

In our development many times it happens that we need to drop a table and as a best practice we write the following syntax as shown in below figure


The Complete Beginner’s Guide to DROP IF EXISTS in SQL SERVER

Now, in SQL SERVER 2016 the same task is super easy. You can write the following syntax to drop the table object


The Complete Beginner’s Guide to DROP IF EXISTS in SQL SERVER
DROP TABLE IF EXISTS TABLENAME

The best part is if suppose the object does not exist then here will be no error execution will continue.

Let me share one more example of Dropping a stored procedure.


The Complete Beginner’s Guide to DROP IF EXISTS in SQL SERVER

Similar, way we can write for following data objects and with the following syntax

Procedure:-

DROP PROCEDURE IF EXISTS Procedure Name

Assembly:-

DROP ASSEMBLY IF EXISTS Assembly Name

ROLENAME :-

DROP ROLE IF EXISTS ROLENAME

TRIGGER :-

DROP TRIGGER IF EXISTS Trigger Name

VIEW:-

DROP VIEW IF EXISTS View Name

RULE:-

DROP RULE IF EXISTS RULENAME

Type:-

DROP TYPE IF EXISTS Type Name

Database:-

DROP DATABASE IF EXISTS Database Name

Schema:-

DROP SCHEMA IF EXISTS Schema Name

User:-

DROP USER IF EXISTS Username

SECURITY POLICY:-

DROP SECURITY POLICY IF EXISTS Policy Name

View :-

DROP VIEW IF EXISTS View Name

FUNCTION:-

DROP FUNCTION IF EXISTS Function Name

SEQUENCE:-

DROP SEQUENCE IF EXISTS Sequence Name

INDEX :-

DROP INDEX IF EXISTS Index Name ON Table Name

Synonym:-

DROP SYNONYM IF EXISTS Synonym Name

I like this feature I am sure you will also like this.

Please, do share your feedback for blog post.

Enjoy !!

本文数据库(mssql)相关术语:熊片数据库 mssql数据库 oracle数据库 pubmed数据库 access数据库 万方数据库

主题: SQLIGGFUCUTICTIDUSSE
分页:12
转载请注明
本文标题:The Complete Beginner’s Guide to DROP IF EXISTS in SQL SERVER
本站链接:http://www.codesec.net/view/484667.html
分享请点击:


1.凡CodeSecTeam转载的文章,均出自其它媒体或其他官网介绍,目的在于传递更多的信息,并不代表本站赞同其观点和其真实性负责;
2.转载的文章仅代表原创作者观点,与本站无关。其原创性以及文中陈述文字和内容未经本站证实,本站对该文以及其中全部或者部分内容、文字的真实性、完整性、及时性,不作出任何保证或承若;
3.如本站转载稿涉及版权等问题,请作者及时联系本站,我们会及时处理。
登录后可拥有收藏文章、关注作者等权限...
技术大类 技术大类 | 数据库(mssql) | 评论(0) | 阅读(23)