UPDATE COUNTY C SET C.KEY_DISTRICT =
	(SELECT D.ID_INTERNAL
	   FROM DISTRICT D
	  WHERE D.CODE = C.DISTRICT_CODE);

UPDATE PARISH P SET P.KEY_COUNTY =
  (SELECT C.ID_INTERNAL
     FROM COUNTY C
    WHERE C.CODE = P.COUNTY_CODE
      AND C.KEY_DISTRICT =
    (SELECT D.ID_INTERNAL
        FROM DISTRICT D
       WHERE D.CODE = P.DISTRICT_CODE));

ALTER TABLE PARISH DROP COLUMN COUNTY_CODE;
ALTER TABLE PARISH DROP COLUMN DISTRICT_CODE;

ALTER TABLE COUNTY DROP COLUMN DISTRICT_CODE;

ALTER TABLE COUNTY ADD UNIQUE KEY `UCOUNTY` (CODE, KEY_DISTRICT);
ALTER TABLE PARISH ADD UNIQUE KEY `UPARISH` (CODE, KEY_COUNTY);
