• SQL 常用判断语句


    我们在做sql更新时,为防止sql重复执行报错,需要对所需要执行的对象进行判断是否存在;

    常用判断脚本如下:

    判断视图是否存在

    IF object_id('viewname') IS not NULL
    begin
     --操作
     --drop view viewname
    end
    判断表是否存在
    IF object_id('tablename') IS NULL
    BEGIN
     --操作
    END
    判断列是否存在
    IF NOT EXISTS (SELECT 1 FROM dbo.syscolumns WHERE [name]='columnname' AND id=object_id('tablename'))
    begin
    
     --操作
    
    end
    判断函数是否存在
     
    IF exists (select 1 from sysobjects where xtype='fn' and name='funcname')
    BEGIN
     --drop function funcname
    end
     
    判断存储过程是否存在
    IF exists (select 1 from sysobjects where xtype='p' and name='procname')
    BEGIN
     --drop proc procname
    end
     
    判断触发器是存在
    IF exists (select * from sysobjects where id=object_id(N'tr_es_Order_upd') and objectproperty(id,N'IsTrigger')=1) 
    begin
    --DROP TRIGGER  tr_es_Order_upd ;
    end
    判断索引是否存在 创建索引
    IF NOT EXISTS (select 1 from sys.indexes where name='index_cb_WarehouseInOutDtl_MaterialsGUID')
    begin
    --操作
    END
  • 相关阅读:
    IfcIndexedColourMap ——Example
    IfcIndexedColourMap
    IfcImageTexture
    IfcFillAreaStyleTiles
    IfcFillAreaStyleHatching
    IfcFillAreaStyle
    IfcExternallyDefinedTextFont
    IfcExternallyDefinedSurfaceStyle
    IfcExternallyDefinedHatchStyle
    IfcDraughtingPreDefinedCurveFont
  • 原文地址:https://www.cnblogs.com/yx007/p/7260925.html
Copyright © 2020-2023  润新知