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

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

declare @cmpid int 
select top 1 @cmpid = pt_cmpid from  deleted   
set @cmpid = isnull(@cmpid,0) 

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

delete mps_programtype_users from deleted where pp_ptid=pt_id 
    return

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