/****** Object:  Trigger [TRG_EST_PROD_CTR_PMC_APAGAR_PRECO_TABELA]    Script Date: 20/07/2016 13:57:54 ******/
IF  EXISTS (SELECT * FROM sys.triggers WHERE object_id = OBJECT_ID(N'[dbo].[TRG_EST_PROD_CTR_PMC_APAGAR_PRECO_TABELA]'))
 DROP TRIGGER [dbo].[TRG_EST_PROD_CTR_PMC_APAGAR_PRECO_TABELA]
 go
CREATE TRIGGER [dbo].[TRG_EST_PROD_CTR_PMC_APAGAR_PRECO_TABELA] ON [dbo].[EST_PROD] FOR UPDATE AS  
begin  
if update(CTR_PMC)  
 begin  
     delete
	   EST_PROD_PRECO_TBL
    from
	   EST_PROD_PRECO_TBL INNER JOIN INSERTED ON
	   EST_PROD_PRECO_TBL.CD_EMP = INSERTED.CD_EMP AND
	   EST_PROD_PRECO_TBL.CD_PROD = INSERTED.CD_PROD  
    WHERE
	  INSERTED.CTR_PMC<>1
 end   
end