技术控

    今日:0| 主题:63445
收藏本版 (1)
最新软件应用技术尽在掌握

[其他] The Complete Beginner’s Guide to DROP IF EXISTS in SQL SERVER

[复制链接]

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

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

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

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

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 !!
刘述平 发表于 2016-10-16 09:34:55
刘述平要成为整个酷辣虫最为脸熟之人!
回复 支持 反对

使用道具 举报

duck1082 发表于 2016-10-16 15:14:36
天灵灵地灵灵,这次一定是沙发!
回复 支持 反对

使用道具 举报

haix610 发表于 2016-10-16 18:15:07
生,容易。活,容易。生活,不容易。  
回复 支持 反对

使用道具 举报

纪兴胜 发表于 2016-11-18 18:16:54
那些路人甲乙丙丁在年生散场的剧场里将五彩纷呈和苍白无力潇洒的演绎。
回复 支持 反对

使用道具 举报

我要投稿

推荐阅读


回页顶回复上一篇下一篇回列表
手机版/c.CoLaBug.com ( 粤ICP备05003221号 | 粤公网安备 44010402000842号 )

© 2001-2017 Comsenz Inc.

返回顶部 返回列表