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

ALTER TABLE [AKUZ].[T_CDA_SECTION_WORK_CHILD]ADD [CdaChildHealthState_UQ] AS (CASE WHEN [CdaChildHealthState] IS NOT NULL THEN NULL ELSE [CdaSectionWorkChildID] END)
GO
CREATE UNIQUE NONCLUSTERED INDEX [UQ_T_CDA_SECTION_WORK_CHILD_CdaChildHealthState] ON [AKUZ].[T_CDA_SECTION_WORK_CHILD] ([CdaChildHealthState] ASC, [CdaChildHealthState_UQ] ASC) ON [PRIMARY]
GO