ALTER TABLE [AKUZ].[T_VISION_DIAGNOSTICS] DROP CONSTRAINT [FK_T_MEDICAL_EXAMINATION_T_VISION_DIAGNOSTICS_MedicalExamination]
GO
EXEC sp_rename 'AKUZ.T_VISION_DIAGNOSTICS.MedicalExamination', 'AmbulanceCardRecord', 'COLUMN';
GO
ALTER TABLE [AKUZ].[T_VISION_DIAGNOSTICS] ADD CONSTRAINT [FK_T_AMBULANCE_CARD_RECORD_T_VISION_DIAGNOSTICS_AmbulanceCardRecord]
FOREIGN KEY([AmbulanceCardRecord]) REFERENCES [AKUZ].[T_AMBULANCE_CARD_RECORD] ([MedicalRecordID])
GO

IF  EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_ID(N'[AKUZ].[T_VISION_DIAGNOSTICS]') AND name = N'UQ_T_VISION_DIAGNOSTICS_AmbulanceCardRecord' and is_unique_constraint <> 1)
DROP INDEX [UQ_T_VISION_DIAGNOSTICS_AmbulanceCardRecord] ON [AKUZ].[T_VISION_DIAGNOSTICS]
IF  EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_ID(N'[AKUZ].[T_VISION_DIAGNOSTICS]') AND name = N'UQ_T_VISION_DIAGNOSTICS_AmbulanceCardRecord' and is_unique_constraint = 1)
ALTER TABLE [AKUZ].[T_VISION_DIAGNOSTICS] DROP CONSTRAINT [UQ_T_VISION_DIAGNOSTICS_AmbulanceCardRecord]
IF  EXISTS (SELECT * FROM sys.columns WHERE object_id = OBJECT_ID(N'[AKUZ].[T_VISION_DIAGNOSTICS]') AND name = N'AmbulanceCardRecord_UQ')
ALTER TABLE [AKUZ].[T_VISION_DIAGNOSTICS] DROP COLUMN [AmbulanceCardRecord_UQ]
GO

/*** ÂÍÈÌÀÍÈÅ! ÑÎÇÄÀÅÒÑß ÓÍÈÊÀËÜÍÛÉ ÈÍÄÅÊÑ, ÏÎËÅ ÍÅ ÌÎÆÅÒ ÁÛÒÜ NULLABLE ***/
CREATE UNIQUE NONCLUSTERED INDEX [UQ_T_VISION_DIAGNOSTICS_AmbulanceCardRecord] ON [AKUZ].[T_VISION_DIAGNOSTICS] ([AmbulanceCardRecord] ASC) ON [PRIMARY]
GO