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

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