ALTER TABLE AKUZ.T_HOSPITAL_DESTINATION ADD "executiondivision" uuid NULL;

UPDATE AKUZ.T_HOSPITAL_DESTINATION hd
SET "executiondivision" = r.Division
from AKUZ.T_MEDICAL_RECORD mr
join AKUZ.T_RESOURCE r on r.ResourceID = mr.Post
where mr.MedicalRecordID = hd.MedicalRecordID;

ALTER TABLE AKUZ.T_HOSPITAL_DESTINATION ALTER COLUMN "executiondivision" SET NOT NULL;

ALTER TABLE AKUZ.T_HOSPITAL_DESTINATION ADD CONSTRAINT FK_T_DIVISION_T_HOSPITAL_DESTINATION_ExecutionDivision
FOREIGN KEY("executiondivision") REFERENCES AKUZ.T_DIVISION (DivisionID);

