DELETE
	EST_PROD_TRANSF_CONF_FASES_ITENS
from
	EST_PROD_TRANSF_CONF_FASES_ITENS LEFT OUTER JOIN EST_PROD_TRANSF_CONF_FASES on
	EST_PROD_TRANSF_CONF_FASES_ITENS.CD_CONTROLE=EST_PROD_TRANSF_CONF_FASES.CD_CONTROLE AND
	EST_PROD_TRANSF_CONF_FASES_ITENS.CD_CTR_FASES=EST_PROD_TRANSF_CONF_FASES.CD_CTR_FASES AND
	EST_PROD_TRANSF_CONF_FASES_ITENS.CD_EMP=EST_PROD_TRANSF_CONF_FASES.CD_EMP
WHERE
	EST_PROD_TRANSF_CONF_FASES.CD_EMP IS NULL
GO
IF  EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_EST_PROD_TRANSF_CONF_FASES_ITENS_EST_PROD_TRANSF_CONF_FASES]'))
begin
	ALTER TABLE [dbo].[EST_PROD_TRANSF_CONF_FASES_ITENS] DROP CONSTRAINT [FK_EST_PROD_TRANSF_CONF_FASES_ITENS_EST_PROD_TRANSF_CONF_FASES]
end
go
ALTER TABLE dbo.EST_PROD_TRANSF_CONF_FASES_ITENS ADD CONSTRAINT
	FK_EST_PROD_TRANSF_CONF_FASES_ITENS_EST_PROD_TRANSF_CONF_FASES FOREIGN KEY
	(
	CD_CONTROLE,
	CD_CTR_FASES,
	CD_EMP
	) REFERENCES dbo.EST_PROD_TRANSF_CONF_FASES
	(
	CD_CONTROLE,
	CD_CTR_FASES,
	CD_EMP
	) ON UPDATE  NO ACTION 
	 ON DELETE  NO ACTION 