IF EXISTS( SELECT * FROM SYS.OBJECTS 
			WHERE NAME ='TRG_EST_NF_ENT_DANFE_PROVISORIO_CIENCIA_OPERACAO'AND TYPE = 'TR')
BEGIN
	DROP TRIGGER dbo.TRG_EST_NF_ENT_DANFE_PROVISORIO_CIENCIA_OPERACAO 
END
GO

CREATE TRIGGER [dbo].[TRG_EST_NF_ENT_DANFE_PROVISORIO_CIENCIA_OPERACAO] ON [dbo].[EST_NF_ENT_DANFE_PROVISORIO_CIENCIA_OPERACAO] FOR  INSERT AS
BEGIN
	--Excluindo pendencia de geracao de confirmacao
	DELETE p
		FROM EST_NF_ENT_DANFE_PROVISORIO_CIENCIA_OPERACAO_PENDENTE p 
		INNER JOIN INSERTED i ON
		p.CD_CTR = i.CD_CTR
END 
