IF EXISTS (SELECT 1 FROM sys.objects WHERE object_id = OBJECT_ID('[dbo].[mps_login_role_delete]') AND type = 'TR')
DROP TRIGGER [dbo].[mps_login_role_delete]
GO
--登陆角色表mps_login_role触发器

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

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

declare @cmpid int 
select top 1 @cmpid = cu_cmpid from  deleted  , mps_login where cu_id=lgu_cuid 
set @cmpid = isnull(@cmpid,0) 

update mps_tableupdated set tu_updated=0 where tu_table='mps_employee'  and tu_cmpid=@cmpid 

delete mps_employee_manager from deleted where cum_cuid=lgu_cuid 
delete mps_employee_manager from deleted where cum_mcuid=lgu_cuid 

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

    return

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