

IF  EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_ID(N'[IES].[T_SCHET_ACT_ITEM]') AND name = N'UQ_T_SCHET_ACT_ITEM_SchetSluchAccomplished' and is_unique_constraint <> 1)
DROP INDEX [UQ_T_SCHET_ACT_ITEM_SchetSluchAccomplished] ON [IES].[T_SCHET_ACT_ITEM]
IF  EXISTS (SELECT * FROM sys.columns WHERE object_id = OBJECT_ID(N'[IES].[T_SCHET_ACT_ITEM]') AND name = N'SchetSluchAccomplished_UQ')
ALTER TABLE [IES].[T_SCHET_ACT_ITEM] DROP COLUMN [SchetSluchAccomplished_UQ]
GO
ALTER TABLE IES.T_SCHET_ACT_ITEM ALTER COLUMN SchetSluchAccomplished uniqueidentifier not null
GO



delete from [IES].[T_SCHET_SLUCH_ONK] where SchetSluch is null
GO

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

IF  EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_ID(N'[IES].[T_SCHET_SLUCH_ONK]') AND name = N'IX_T_SCHET_SLUCH_ONK_OmsSchetSluch')
DROP INDEX [IX_T_SCHET_SLUCH_ONK_OmsSchetSluch] ON [IES].[T_SCHET_SLUCH_ONK]
IF  EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_ID(N'[IES].[T_SCHET_SLUCH_ONK]') AND name = N'IX_T_SCHET_SLUCH_ONK_SchetSluch')
DROP INDEX [IX_T_SCHET_SLUCH_ONK_SchetSluch] ON [IES].[T_SCHET_SLUCH_ONK]
GO
ALTER TABLE IES.T_SCHET_SLUCH_ONK ALTER COLUMN SchetSluch uniqueidentifier not null
GO
GO
CREATE UNIQUE NONCLUSTERED INDEX [UQ_T_SCHET_SLUCH_ONK_SchetSluch] ON [IES].[T_SCHET_SLUCH_ONK] ([SchetSluch] ASC) ON [PRIMARY]
GO

IF  EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_ID(N'[IES].[T_SCHET_SLUCH_ONK_DIAG]') AND name = N'IX_T_SCHET_SLUCH_ONK_DIAG_SchetSluchOnk')
DROP INDEX [IX_T_SCHET_SLUCH_ONK_DIAG_SchetSluchOnk] ON [IES].[T_SCHET_SLUCH_ONK_DIAG]
GO
ALTER TABLE IES.T_SCHET_SLUCH_ONK_DIAG ALTER COLUMN SchetSluchOnk uniqueidentifier not null
GO
CREATE NONCLUSTERED INDEX [IX_T_SCHET_SLUCH_ONK_DIAG_SchetSluchOnk] ON [IES].[T_SCHET_SLUCH_ONK_DIAG]([SchetSluchOnk] ASC)
GO

IF  EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_ID(N'[IES].[T_SCHET_SLUCH_ONK_PROT]') AND name = N'IX_T_SCHET_SLUCH_ONK_PROT_SchetSluchOnk')
DROP INDEX [IX_T_SCHET_SLUCH_ONK_PROT_SchetSluchOnk] ON [IES].[T_SCHET_SLUCH_ONK_PROT]
GO
ALTER TABLE IES.T_SCHET_SLUCH_ONK_PROT ALTER COLUMN SchetSluchOnk uniqueidentifier not null
GO
CREATE NONCLUSTERED INDEX [IX_T_SCHET_SLUCH_ONK_PROT_SchetSluchOnk] ON [IES].[T_SCHET_SLUCH_ONK_PROT]([SchetSluchOnk] ASC)
GO

IF  EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_ID(N'[IES].[T_SCHET_SLUCH_NAZ]') AND name = N'IX_T_SCHET_SLUCH_NAZ_SchetSluch')
DROP INDEX [IX_T_SCHET_SLUCH_NAZ_SchetSluch] ON [IES].[T_SCHET_SLUCH_NAZ]
GO
ALTER TABLE IES.T_SCHET_SLUCH_NAZ ALTER COLUMN SchetSluch uniqueidentifier not null
GO
CREATE NONCLUSTERED INDEX [IX_T_SCHET_SLUCH_NAZ_SchetSluch] ON [IES].[T_SCHET_SLUCH_NAZ]([SchetSluch] ASC)
GO

IF  EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_ID(N'[IES].[T_SCHET_SLUCH_LS]') AND name = N'IX_T_SCHET_SLUCH_LS_SchetSluch')
DROP INDEX [IX_T_SCHET_SLUCH_LS_SchetSluch] ON [IES].[T_SCHET_SLUCH_LS]
GO
ALTER TABLE IES.T_SCHET_SLUCH_LS ALTER COLUMN SchetSluch uniqueidentifier not null
GO
CREATE NONCLUSTERED INDEX [IX_T_SCHET_SLUCH_LS_SchetSluch] ON [IES].[T_SCHET_SLUCH_LS]([SchetSluch] ASC)
GO

IF  EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_ID(N'[IES].[T_SCHET_SLUCH_CONS]') AND name = N'IX_T_SCHET_SLUCH_CONS_SchetSluch')
DROP INDEX [IX_T_SCHET_SLUCH_CONS_SchetSluch] ON [IES].[T_SCHET_SLUCH_CONS]
GO
IF  EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_ID(N'[IES].[T_SCHET_SLUCH_CONS]') AND name = N'IX_T_SCHET_SLUCH_CONS_OmsSchetSluch')
DROP INDEX [IX_T_SCHET_SLUCH_CONS_OmsSchetSluch] ON [IES].[T_SCHET_SLUCH_CONS]
GO
IF  EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_ID(N'[IES].[T_SCHET_SLUCH_CONS]') AND name = N'IX_T_SCHET_SLUCH_CONS_OmsSchetSluch')
DROP INDEX [IX_SCHET_SLUCH_CONS_OmsSchetSluch] ON [IES].[T_SCHET_SLUCH_CONS]
GO
ALTER TABLE IES.T_SCHET_SLUCH_CONS ALTER COLUMN SchetSluch uniqueidentifier not null
GO
CREATE NONCLUSTERED INDEX [IX_T_SCHET_SLUCH_CONS_SchetSluch] ON [IES].[T_SCHET_SLUCH_CONS]([SchetSluch] ASC)
GO
IF  EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_ID(N'[IES].[T_KSG]') AND name = N'IX_T_KSG_SchetSluch')
DROP INDEX [IX_T_KSG_SchetSluch] ON [IES].[T_KSG]
GO
ALTER TABLE IES.T_KSG ALTER COLUMN SchetSluch uniqueidentifier not null
GO
CREATE NONCLUSTERED INDEX [IX_T_KSG_SchetSluch] ON [IES].[T_KSG]([SchetSluch] ASC)