IF NOT OBJECT_ID('TRG_EST_PROD_CPL_DEMANDA_PROC_CPL_LIB_EXCLUI_PENDENCIA') IS NULL
	BEGIN 
		DROP TRIGGER TRG_EST_PROD_CPL_DEMANDA_PROC_CPL_LIB_EXCLUI_PENDENCIA 
	END 

GO
CREATE TRIGGER [dbo].[TRG_EST_PROD_CPL_DEMANDA_PROC_CPL_LIB_EXCLUI_PENDENCIA] ON [dbo].[EST_PROD_CPL_DEMANDA_PROC_CPL_LIB] FOR INSERT AS
DELETE FROM p FROM EST_PROD_CPL_DEMANDA_PROC_CPL_LIB_PENDENTE p WHERE EXISTS
    (SELECT * FROM INSERTED WHERE CD_CTR_PROC_CPL=p.CD_CTR_PROC_CPL)

