UPDATE vn.postCode pc LEFT JOIN vn.zoneGeo zg ON zg.id = pc.geoFk SET pc.geoFk = NULL WHERE zg.id IS NULL; ALTER TABLE vn.postCode ADD CONSTRAINT postCode_zoneGeo_FK FOREIGN KEY (geoFk) REFERENCES vn.zoneGeo(id) ON DELETE RESTRICT ON UPDATE CASCADE;