delete
	EST_NF_SAI_IT_RECEITA
FROM
	EST_NF_SAI_IT_RECEITA left outer join GLB_MEDICOS on
	EST_NF_SAI_IT_RECEITA.cd_emp = GLB_MEDICOS.cd_emp and
	EST_NF_SAI_IT_RECEITA.CD_MEDICO_REC = GLB_MEDICOS.cd_ctr 
where
	GLB_MEDICOS.cd_ctr is null
GO
IF  NOT EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_EST_NF_SAI_IT_RECEITA_GLB_MEDICOS]'))
begin
ALTER TABLE dbo.EST_NF_SAI_IT_RECEITA ADD CONSTRAINT
	FK_EST_NF_SAI_IT_RECEITA_GLB_MEDICOS FOREIGN KEY
	(
	CD_EMP,
	CD_MEDICO_REC
	) REFERENCES dbo.GLB_MEDICOS
	(
	CD_EMP,
	CD_CTR
	) ON UPDATE  NO ACTION 
	 ON DELETE  NO ACTION 
end