IF EXISTS ( SELECT 1 FROM SYS.TRIGGERS WHERE NAME = 'TRG_EST_NF_ENT_NFE_PEND_EXCLUSAO' )
BEGIN
	DROP TRIGGER TRG_EST_NF_ENT_NFE_PEND_EXCLUSAO
END
GO
CREATE TRIGGER TRG_EST_NF_ENT_NFE_PEND_EXCLUSAO ON EST_NF_ENT_NFE 
FOR INSERT AS
	--Apgando a pendência de saída de nota fiscal eletronica
	DELETE 
		d
	FROM 
		EST_NF_ENT_NFE_PEND d INNER JOIN INSERTED t ON
		t.CD_EMP        = d.CD_EMP  
		AND t.CD_FILIAL = d.CD_FILIAL
		AND t.CD_NF     = d.CD_NF
