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

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

    -- 写回历史表
    insert into mps_account_history(acc_cmpid,acc_type,acc_category,acc_fiid,acc_date,acc_objid,acc_origin,acc_value,acc_used,acc_changed,acc_suspended,acc_ready) 
    select acc_cmpid,acc_type,acc_category,acc_fiid,acc_date,acc_objid,acc_origin,acc_value,acc_used,acc_changed,acc_suspended,acc_ready 
    from deleted  
    --- 写回结束 
    return

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