-- Tables

-- Alters

ALTER TABLE [VMP].[T_VMP_PLAN] ADD [EhrRusFmqd3f8d1m] uniqueidentifier NULL
GO
UPDATE vp
SET [EhrRusFmqd3f8d1m] = (select top 1 ehh.EhrRusID 
								from EHR.T_EHR_RUS_FMQD3F8D1M ehh
									join EHR.T_EHR_RUS erhh on erhh.EhrRusID = ehh.EhrRusID
								where erhh.IdEHR = Cast(eh.CodeEHR as int))
from [VMP].[T_VMP_PLAN] vp 
join EHR.T_EHR_RUS eh on eh.EhrRusID = vp.EhrRusOo4khhdi90

GO
ALTER TABLE [VMP].[T_VMP_PLAN] ALTER COLUMN [EhrRusFmqd3f8d1m] uniqueidentifier NOT NULL
GO

ALTER TABLE [VMP].[T_VMP_PLAN] ADD CONSTRAINT [FK_T_EHR_RUS_FMQD3F8D1M_T_VMP_PLAN_EhrRusFmqd3f8d1m]
FOREIGN KEY([EhrRusFmqd3f8d1m]) REFERENCES [EHR].[T_EHR_RUS_FMQD3F8D1M] ([EhrRusID])
GO



ALTER TABLE [VMP].T_VMP_EXECUTION_RESULT_STAGE ADD [EhrRusFmqd3f8d1m] uniqueidentifier NULL
GO
UPDATE vp
SET [EhrRusFmqd3f8d1m] = (select top 1 ehh.EhrRusID 
								from EHR.T_EHR_RUS_FMQD3F8D1M ehh
									join EHR.T_EHR_RUS erhh on erhh.EhrRusID = ehh.EhrRusID
								where erhh.IdEHR = Cast(eh.CodeEHR as int))
from [VMP].T_VMP_EXECUTION_RESULT_STAGE vp 
join EHR.T_EHR_RUS eh on eh.EhrRusID = vp.EhrRusOo4khhdi90

GO
ALTER TABLE [VMP].T_VMP_EXECUTION_RESULT_STAGE ALTER COLUMN [EhrRusFmqd3f8d1m] uniqueidentifier NOT NULL
GO

ALTER TABLE [VMP].T_VMP_EXECUTION_RESULT_STAGE ADD CONSTRAINT [FK_T_EHR_RUS_FMQD3F8D1M_T_VMP_EXECUTION_RESULT_STAGE_EhrRusFmqd3f8d1m]
FOREIGN KEY([EhrRusFmqd3f8d1m]) REFERENCES [EHR].[T_EHR_RUS_FMQD3F8D1M] ([EhrRusID])
GO
