标签:pre 更新 not ros dex objects 语句 sts weight
我们在做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
标签:pre 更新 not ros dex objects 语句 sts weight
原文地址:http://www.cnblogs.com/yx007/p/7260925.html