CREATE TABLE temp_dnfact_mkb
(
    DnFactID UNIQUEIDENTIFIER,
    DS	     VARCHAR(20) NOT NULL
)
GO


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
GO


ALTER TABLE RDS.T_DN_FACT
    DROP CONSTRAINT FK_T_MKB_T_DN_FACT_DS
GO


ALTER TABLE RDS.T_DN_FACT
    DROP COLUMN DS
GO


ALTER TABLE RDS.T_DN_FACT ADD DS varchar(20)
GO


UPDATE pb
SET DS = tmp.DS
FROM RDS.T_DN_FACT pb
JOIN temp_dnfact_mkb tmp ON tmp.DnFactId = pb.DnFactId
GO


DROP TABLE temp_dnfact_mkb
GO