delete
	PDV_VD_IT_REC
FROM
	PDV_VD_IT_REC left outer join GLB_MEDICOS on
	PDV_VD_IT_REC.cd_emp = GLB_MEDICOS.cd_emp and
	PDV_VD_IT_REC.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_PDV_VD_IT_REC_GLB_MEDICOS]'))
begin
ALTER TABLE dbo.PDV_VD_IT_REC ADD CONSTRAINT
	FK_PDV_VD_IT_REC_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