IF EXISTS (SELECT 1 FROM sys.objects WHERE object_id = OBJECT_ID('[dbo].[mps_account_operation_delete]') AND type = 'TR')
DROP TRIGGER [dbo].[mps_account_operation_delete]
GO

   
CREATE trigger [dbo].[mps_account_operation_delete] on [dbo].[mps_account_operation] for delete as
begin
    declare
       @numrows  int,
       @errno    int,
       @errmsg   varchar(255)

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

    
insert into mps_account_operation_history(
accop_id,accop_cmpid,accop_type,accop_category,accop_fiid,accop_date,accop_objid,accop_opdate,accop_operation,
accop_value,accop_bizid,accop_no,accop_ordid,accop_jbid) 
select accop_id,accop_cmpid,accop_type,accop_category,accop_fiid,accop_date,accop_objid,accop_opdate,accop_operation,
accop_value,accop_bizid,accop_no,accop_ordid,accop_jbid 
from deleted 

    return

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