CREATE TEMP TABLE temp_dnfact_mkb
(
    DnFactID UUID,
    DS VARCHAR(20) NOT NULL
);

INSERT INTO temp_dnfact_mkb (DnFactID, DS)
SELECT pb.DnFactID,
       mkb.MCBCode
FROM RDS.T_DN_FACT pb
JOIN RDS.T_MKB mkb ON mkb.MkbID = pb.DS;

ALTER TABLE RDS.T_DN_FACT
    DROP CONSTRAINT FK_T_MKB_T_DN_FACT_DS;

ALTER TABLE RDS.T_DN_FACT
    DROP COLUMN DS;

ALTER TABLE RDS.T_DN_FACT ADD COLUMN DS varchar(20);

UPDATE RDS.T_DN_FACT pb
SET DS = tmp.DS
FROM temp_dnfact_mkb tmp
WHERE tmp.DnFactID = pb.DnFactID;

DROP TABLE temp_dnfact_mkb;
