-- Tables

-- Alters

ALTER TABLE [AKUZ].[T_MEDICAL_EXAMINATION_DATA] ADD [CurrentDispanserisationInit] uniqueidentifier NULL
GO

ALTER TABLE [AKUZ].[T_MEDICAL_EXAMINATION_DATA] ADD CONSTRAINT [FK_T_DISPANSERISATION_INIT_T_MEDICAL_EXAMINATION_DATA_CurrentDispanserisationInit]
FOREIGN KEY([CurrentDispanserisationInit]) REFERENCES [AKUZ].[T_DISPANSERISATION_INIT] ([MedicalRecordID])


update akuz.T_MEDICAL_EXAMINATION_DATA 
set CurrentDispanserisationInit = t1.MedicalRecordID
from akuz.T_DISPANSERISATION_INIT t1 inner join akuz.T_MEDICAL_EXAMINATION_DATA t2 
on t1.MedicalExaminationData = t2.MedicalExaminationDataID where t1.MedicalExaminationData is not null 
