IF EXISTS (SELECT * FROM SYS.TRIGGERS WHERE NAME = 'TRG_EST_PROD_PRECO_ALT_CPL_BLOQUEIO_EXCLUI_PENDENCIA')
begin
	DROP TRIGGER [dbo].[TRG_EST_PROD_PRECO_ALT_CPL_BLOQUEIO_EXCLUI_PENDENCIA]
end
go
CREATE TRIGGER [dbo].[TRG_EST_PROD_PRECO_ALT_CPL_BLOQUEIO_EXCLUI_PENDENCIA] ON [dbo].[EST_PROD_PRECO_ALT_CPL_BLOQUEIO] FOR INSERT AS
DELETE FROM p FROM EST_PROD_PRECO_ALT_CPL_LIB_PENDENTE p WHERE EXISTS
    (SELECT * FROM INSERTED WHERE 
				P.CD_EMP=INSERTED.CD_EMP AND
				P.CD_ALT_PRECO=INSERTED.CD_ALT_PRECO AND
				P.CD_PROD=INSERTED.CD_PROD)

DELETE FROM p FROM EST_PROD_PRECO_ALT_CPL_PENDENTE_APLICACAO_PRECO p WHERE EXISTS
    (SELECT * FROM INSERTED WHERE 
				P.CD_EMP=INSERTED.CD_EMP AND
				P.CD_ALT_PRECO=INSERTED.CD_ALT_PRECO AND
				P.CD_PROD=INSERTED.CD_PROD)
