IF EXISTS (SELECT 1 FROM sys.objects WHERE object_id = OBJECT_ID('[dbo].[mps_biztype_delete]') AND type = 'TR')
DROP TRIGGER [dbo].[mps_biztype_delete]
GO
CREATE trigger [dbo].[mps_biztype_delete] on [dbo].[mps_biztype] for delete as
begin
    declare
       @maxcard  int,
       @numrows  int,
       @numnull  int,
       @errno    int,
       @errmsg   varchar(255)

    select  @numrows = @@rowcount
    if @numrows = 0
       return

declare @cmpid int 
select top 1 @cmpid = biz_cmpid from  deleted   
set @cmpid = isnull(@cmpid,0) 

insert into mps_sync(sk_type,sk_bizid,sk_objid,sk_operation,sk_tag2) 
select 20 , biz_id , biz_id , -1 , 0 from deleted 

delete mps_biztype2 from deleted where biz2_bizid=biz_id 
delete mps_biztype_comefrom from deleted where bs_bizid=biz_id 
delete mps_biztype_decision from deleted where bd_bizid=biz_id
delete mps_biztype_relation from deleted where br_bizid=biz_id 
delete mps_biztype_users from deleted where bp_bizid=biz_id 
delete mps_biztype_query from deleted where bql_bizid=biz_id 
    return

/*  Errors handling  */
error:
    -- raiserror @errno @errmsg
      rollback  transaction
end