delete 
	EST_META_LINHA
from
	EST_META_LINHA left outer JOIN EST_META_FILIAL ON
	EST_META_LINHA.CD_EMP = EST_META_FILIAL.CD_EMP AND
	EST_META_LINHA.CD_META_LINHA = EST_META_FILIAL.CD_META_FILIAL
where
	EST_META_LINHA.CD_EMP = 1
	AND EST_META_FILIAL.CD_META_FILIAL is null
GO
IF NOT OBJECT_ID ('FK_EST_META_LINHA_EST_META_FILIAL') IS NULL
	BEGIN
		ALTER TABLE [dbo].[EST_META_LINHA] DROP CONSTRAINT [FK_EST_META_LINHA_EST_META_FILIAL]
	END

GO
ALTER TABLE dbo.EST_META_LINHA ADD CONSTRAINT
	FK_EST_META_LINHA_EST_META_FILIAL FOREIGN KEY
	(
	CD_EMP,
	CD_META_LINHA
	) REFERENCES dbo.EST_META_FILIAL
	(
	CD_EMP,
	CD_META_FILIAL
	) ON UPDATE  NO ACTION 
	 ON DELETE  NO ACTION 