When we do the SQL update, in order to prevent the SQL to repeat the error, we need to judge the existence of the object to be executed;
Common judgment scripts are as follows:
To determine whether a view exists
IF object_id ('viewname'is notNULLbegin-- operation --drop view viewnameEnd
determine if a table exists
IF object_id ('tablename'isNULLBEGIN-- operation END
determine if a column exists
IF not EXISTS(SELECT 1 fromDbo.syscolumnsWHERE [name]='ColumnName' andId=object_id('TableName'))begin --OperationEnd
determine if a function exists
IF exists (Select1from where xtype='fn'and name='funcname')BEGIN-- drop function FuncName End
determine if a stored procedure exists
IF exists (Select1from where xtype='P'and name='procname')BEGIN-- drop proc ProcName End
determine if a trigger is present
IF exists(Select * fromsysobjectswhereId=object_id(N'tr_es_order_upd') and ObjectProperty(Id,n'Istrigger')=1) begin--DROP TRIGGER tr_es_order_upd;End
To determine if an index exists CREATE index
IF not EXISTS (Select1fromwhere name='index_cb_warehouseinoutdtl_ Materialsguid')begin-- operation END
SQL Common Judgment statement