IF EXISTS(SELECT NAME FROM SYS.TRIGGERS WHERE NAME = 'TRG_EST_PROD_TABLOIDE_FILIAL_DELETADO')
BEGIN
	DROP TRIGGER TRG_EST_PROD_TABLOIDE_FILIAL_DELETADO;
END
GO
GO
CREATE TRIGGER [dbo].[TRG_EST_PROD_TABLOIDE_FILIAL_DELETADO] ON [dbo].[EST_PROD_TABLOIDE_FILIAL] FOR DELETE AS
BEGIN

	--Tabela de controle de alteracao
	INSERT INTO EST_PROD_TABLOIDE_FILIAL_DELETADO (CD_EMP,
										CD_TABLOIDE,	
										CD_FILIAL,	
										DT_CAD,
										FLAG_PROCESSADO)
		SELECT 
			DELETED.CD_EMP,
			DELETED.CD_TABLOIDE,	
			DELETED.CD_FILIAL,	
			GETDATE(),
			0
		FROM 
			DELETED
END

