IF EXISTS (SELECT 1 FROM sys.objects WHERE object_id = OBJECT_ID('[dbo].[mps_permission_insert]') AND type = 'TR')
DROP TRIGGER [dbo].[mps_permission_insert]
GO
CREATE  trigger [dbo].[mps_permission_insert] on [dbo].[mps_permission] for insert as
begin
    
declare @cmpid int 
select top 1 @cmpid = mp_cmpid from  inserted 
set @cmpid = isnull(@cmpid,0)

insert into mps_sync(sk_type,sk_bizid,sk_tag2,sk_operation,sk_objid) 
   select 200,0,0,1,mp_id from inserted 
   
if (not exists (select 1 from mps_command where cmd_cmpid=@cmpid and cmd_code='rightPart')) 
begin
insert into mps_command(cmd_code,cmd_cmpid) values('rightPart',@cmpid) 
end 
end