IF EXISTS(SELECT * FROM SYS.triggers WHERE NAME = 'TRG_EST_PROD_GERA_PEND_ENVIO_GT')
BEGIN
	DROP TRIGGER TRG_EST_PROD_GERA_PEND_ENVIO_GT
END

GO

CREATE TRIGGER 
	TRG_EST_PROD_GERA_PEND_ENVIO_GT
ON
	EST_PROD
AFTER INSERT
AS
BEGIN
	INSERT INTO
		EST_PROD_GT_ENVIO_PENDENTE (CD_EMP, CD_PROD, ORIGEM)
	SELECT
		CD_EMP, CD_PROD, 0
	FROM
		INSERTED
	WHERE
		FLAG_NAO_ATUALIZA_GT = 0
END
