原文:SQL Server 2016新特性:DROP IF EXISTS



在我们写T-SQL要删除某个对象(表、存储过程等)时,一般会习惯先用IF语句判断该对象是否存在,然后DROP,比如:

旧版本:

IF OBJECT_ID('dbo.PERSON','U') IS NOT NULL
DROP TABLE PERSON IF EXISTS (SELECT * FROM sys.objects where name = 'PERSON')
DROP TABLE PERSON

SQL Server 2016简化了这一操作,通过下面一句简洁的SQL即可实现:

新版本(SQL Server 2016):

DROP TABLE  IF EXISTS PERSON

DROP IF EXISTS的语法如下:

DROPobject_type
IFEXISTSobject_name

能够用于DROP的object_type,如Tables, Database, Function, Trigger, Stored Procedure, Column, User, Type, View, Schema,皆可套用,比如:

ALTER TABLE PERSON
DROP COLUMN If EXISTS NAME

SQL Server 2016新特性:DROP IF EXISTS的更多相关文章

  1. SQL Server ->> 深入探讨SQL Server 2016新特性之 --- Temporal Table(历史表)

    原文:SQL Server ->> 深入探讨SQL Server 2016新特性之 --- Temporal Table(历史表) 作为SQL Server 2016(CTP3.x)的另一 ...

  2. SQL Server 2016新特性:列存储索引新特性

    SQL Server 2016新特性:列存储索引新特性 行存储表可以有一个可更新的列存储索引,之前非聚集的列存储索引是只读的. 非聚集的列存储索引支持筛选条件. 在内存优化表中可以有一个列存储索引,可 ...

  3. SQL Server ->> 深入探讨SQL Server 2016新特性之 --- Row-Level Security(行级别安全控制)

    SQL Server 2016 CPT3中包含了一个新特性叫Row Level Security(RLS),允许数据库管理员根据业务需要依据客户端执行脚本的一些特性控制客户端能够访问的数据行,比如,我 ...

  4. SQL Server 2016新特性:Live Query Statistics

    SSMS可以提供可以查看正在执行的计划.live query plan可以查看一个查询的执行过程,从一个查询计划操作到另外一个查询计划操作.live query plan提供了整体的查询运行进度和操作 ...

  5. SQL Server ->> SQL Server 2016新特性之 --- Query Store

    前言 SQL Server 2016引入新的查询语句性能监控.调试和优化工具/功能 -- Query Store.以前我们发现一条查询语句性能突然下降,我们要去找出问题的所在往往需要通过调用一些DMV ...

  6. SQL Server ->> SQL Server 2016新特性之 -- Dynamic Data Masking

    Dynamic Data Masking是为了防止敏感数据暴露给未经授权的用户,以一种最小开销和维护成本的形式.Dynamic Data Masking用于表的字段,相当于盖住字段数据的一部分.比如一 ...

  7. SQL Server ->> SQL Server 2016新特性之 -- sp_set_session_context存储过程和SESSION_CONTEXT函数

    sp_set_session_context存储过程和SESSION_CONTEXT函数出现在了SQL Server 2016 CTP3.0上.它俩配合起来的作用是sp_set_session_con ...

  8. sql server 2016新特性 查询存储(Query Store)的性能影响

    前段时间给客户处理性能问题,遇到一个新问题, 客户的架构用的是 alwayson ,并且硬件用的是4路96核心,内存1T ,全固态闪存盘,sql server 2016 . 问题  描述 客户经常出现 ...

  9. SQL Server 2016新特性: 对JSON的支持

     SQL Server 2005开始支持XML数据类型,提供原生的XML数据类型.XML索引及各种管理或输出XML格式的函数.随着JSON的流行,SQL Server2016开始支持JSON数据类 ...

随机推荐

  1. [NPM] Run npm scripts with git hooks

    In this lesson we will look about how we can integrate with git hooks to help enforce a certain leve ...

  2. Jquery前端分页插件pagination同步加载和异步加载

    上一篇文章介绍了Jquery前端分页插件pagination的基本使用方法和使用案例,大致原理就是一次性加载所有的数据再分页.https://www.jianshu.com/p/a1b8b1db025 ...

  3. Methods and systems to control virtual machines

    Methods and systems are provided to control the execution of a virtual machine (VM). A VM Monitor (V ...

  4. Role-based access control modeling and auditing system

    A role-based access control (RBAC) modeling and auditing system is described that enables a user to  ...

  5. Oracle数据库表空间 数据文件 用户 以及表创建的SQL代码

    --create the tablespace CREATE SMALLFILE TABLESPACE "TABLE_CONTAINER" --创建表空间 DATAFILE 'E: ...

  6. Java数组课后习题

    package javafirst; import java.util.Arrays; class Show{ public void showArray(int[] arr){ for(int i ...

  7. 【17.69%】【codeforces 659F】Polycarp and Hay

    time limit per test4 seconds memory limit per test512 megabytes inputstandard input outputstandard o ...

  8. git如何更新fork的repository(Fork一个别人的repository,做了一些改动,再合并别人的更新)

    Fork一个别人的repository,做了一些改动,想提交pull request的时候,发现原先别人的repository已经又有了一些更新了,这个时候想使得自己fork出的repository也 ...

  9. How to configure spring boot through annotations in order to have something similar to <jsp-config> in web.xml?

    JSP file not rendering in Spring Boot web application You will need not one but two dependencies (ja ...

  10. C# 创建文件释放 Dispose()

    System.IO.File.Create("文件路径") 前提确保有此路径, 否则会报错 本以为创建文件是会自动释放的, 结果没有自动释放 , fs.Write(response ...