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

ALTER TABLE [AKUZ].[T_MOVEMENT_RESULT_LEK_PREP_LINK]ADD [OutcomeOfInspection_UQ] AS (CASE WHEN [OutcomeOfInspection] IS NOT NULL THEN NULL ELSE [MovementResultLekPrepLinkID] END)
GO
CREATE UNIQUE NONCLUSTERED INDEX [UQ_T_MOVEMENT_RESULT_LEK_PREP_LINK_OutcomeOfInspection] ON [AKUZ].[T_MOVEMENT_RESULT_LEK_PREP_LINK] ([OutcomeOfInspection] ASC, [OutcomeOfInspection_UQ] ASC) ON [PRIMARY]
GO
