
IF EXISTS (SELECT * FROM sys.objects WHERE name = 'FK_T_ECHOCARDIOGRAPHY_PROTOCOL_T_ANTHROPOMETRIC_PHYSIOLOGICAL_INDICATOR_EchocardiographyProtocol')
BEGIN
	ALTER TABLE [AKUZ].[T_ANTHROPOMETRIC_PHYSIOLOGICAL_INDICATOR] DROP CONSTRAINT [FK_T_ECHOCARDIOGRAPHY_PROTOCOL_T_ANTHROPOMETRIC_PHYSIOLOGICAL_INDICATOR_EchocardiographyProtocol]
END;

IF EXISTS (SELECT * FROM sys.indexes WHERE name = 'UQ_T_ANTHROPOMETRIC_PHYSIOLOGICAL_INDICATOR_EchocardiographyProtocol')
BEGIN
	DROP INDEX [UQ_T_ANTHROPOMETRIC_PHYSIOLOGICAL_INDICATOR_EchocardiographyProtocol] ON [AKUZ].[T_ANTHROPOMETRIC_PHYSIOLOGICAL_INDICATOR]
END;

IF EXISTS (SELECT * FROM sys.columns WHERE name = 'EchocardiographyProtocol_UQ')
BEGIN
	ALTER TABLE [AKUZ].[T_ANTHROPOMETRIC_PHYSIOLOGICAL_INDICATOR] DROP COLUMN EchocardiographyProtocol_UQ
END;

ALTER TABLE [AKUZ].[T_ANTHROPOMETRIC_PHYSIOLOGICAL_INDICATOR] DROP COLUMN [EchocardiographyProtocol]
GO

ALTER TABLE [AKUZ].[T_ANTHROPOMETRIC_PHYSIOLOGICAL_INDICATOR] ADD [EchocardiographyProtocol] uniqueidentifier NULL
GO

ALTER TABLE [AKUZ].[T_ANTHROPOMETRIC_PHYSIOLOGICAL_INDICATOR] ADD CONSTRAINT [FK_T_DIAGNOSTICS_RESULTS_T_ANTHROPOMETRIC_PHYSIOLOGICAL_INDICATOR_EchocardiographyProtocol]
FOREIGN KEY([EchocardiographyProtocol]) REFERENCES [AKUZ].[T_DIAGNOSTICS_RESULTS] ([MedicalRecordID])
GO


IF EXISTS (SELECT * FROM sys.objects WHERE name = 'FK_T_ECHOCARDIOGRAPHY_PROTOCOL_T_BASIC_ECHOCARDIOGRAPHY_PROTOCOL_EchocardiographyProtocol')
BEGIN
	ALTER TABLE [AKUZ].[T_BASIC_ECHOCARDIOGRAPHY_PROTOCOL] DROP CONSTRAINT [FK_T_ECHOCARDIOGRAPHY_PROTOCOL_T_BASIC_ECHOCARDIOGRAPHY_PROTOCOL_EchocardiographyProtocol]
END;

IF EXISTS (SELECT * FROM sys.indexes WHERE name = 'UQ_T_BASIC_ECHOCARDIOGRAPHY_PROTOCOL_EchocardiographyProtocol')
BEGIN
	DROP INDEX [UQ_T_BASIC_ECHOCARDIOGRAPHY_PROTOCOL_EchocardiographyProtocol] ON [AKUZ].[T_BASIC_ECHOCARDIOGRAPHY_PROTOCOL]
END;

IF EXISTS (SELECT * FROM sys.columns WHERE name = 'EchocardiographyProtocol_UQ')
BEGIN
	ALTER TABLE [AKUZ].[T_BASIC_ECHOCARDIOGRAPHY_PROTOCOL] DROP COLUMN EchocardiographyProtocol_UQ
END;

ALTER TABLE [AKUZ].[T_BASIC_ECHOCARDIOGRAPHY_PROTOCOL] DROP COLUMN [EchocardiographyProtocol]
GO

ALTER TABLE [AKUZ].[T_BASIC_ECHOCARDIOGRAPHY_PROTOCOL] ADD [EchocardiographyProtocol] uniqueidentifier NULL
GO

ALTER TABLE [AKUZ].[T_BASIC_ECHOCARDIOGRAPHY_PROTOCOL] ADD CONSTRAINT [FK_T_DIAGNOSTICS_RESULTS_T_BASIC_ECHOCARDIOGRAPHY_PROTOCOL_EchocardiographyProtocol]
FOREIGN KEY([EchocardiographyProtocol]) REFERENCES [AKUZ].[T_DIAGNOSTICS_RESULTS] ([MedicalRecordID])
GO