-- Tables

-- Alters

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

ALTER TABLE [AKUZ].[T_MEDICAL_EXAMINATION_DATA] ADD CONSTRAINT [FK_T_OUTCOME_OF_INSPECTION_T_MEDICAL_EXAMINATION_DATA_OutcomeRecord]
FOREIGN KEY([OutcomeRecord]) REFERENCES [AKUZ].[T_OUTCOME_OF_INSPECTION] ([MedicalRecordID])
GO


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