IF EXISTS (SELECT 1 FROM sys.objects WHERE object_id = OBJECT_ID('[dbo].[mps_csttype_delete]') AND type = 'TR')
DROP TRIGGER [dbo].[mps_csttype_delete]
GO
--客户类别删除的触发器
CREATE trigger [dbo].[mps_csttype_delete] on [dbo].[mps_csttype] for delete as
begin
    
declare @cmpid int 
select top 1 @cmpid = ct_cmpid from  deleted 
set @cmpid = isnull(@cmpid,0)

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

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

delete mps_csttype_users from deleted where cp_ctid=ct_id 

delete mps_role from deleted where rl_cmpid=@cmpid and rl_value=1000000+ct_id  
    
end