CREATE TABLE temp_pb_mkb
(
    PatientBenefitsID UUID,
    Mkb               VARCHAR(20) NOT NULL
);

INSERT INTO temp_pb_mkb (PatientBenefitsID, Mkb)
SELECT pb.PatientBenefitsID,
       mkb.MCBCode
FROM AKUZ.T_PATIENT_BENEFITS pb
JOIN akuz.T_MKB mkb ON mkb.MkbID = pb.Mkb;

ALTER TABLE AKUZ.T_PATIENT_BENEFITS
    DROP CONSTRAINT FK_T_MKB_T_PATIENT_BENEFITS_Mkb;

ALTER TABLE AKUZ.T_PATIENT_BENEFITS
    DROP COLUMN Mkb;

ALTER TABLE AKUZ.T_PATIENT_BENEFITS 
    ADD COLUMN Mkb VARCHAR(20);

UPDATE AKUZ.T_PATIENT_BENEFITS pb
SET Mkb = tmp.Mkb
FROM temp_pb_mkb tmp
WHERE tmp.PatientBenefitsID = pb.PatientBenefitsID;

DROP TABLE temp_pb_mkb;
