IF  EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_ID(N'[EMDR].[T_EMPR]') AND name = N'ix_EMPR_Kind')
DROP INDEX [ix_EMPR_Kind] ON [EMDR].[T_EMPR]
GO
CREATE INDEX [ix_EMPR_Kind] ON [EMDR].[T_EMPR] ( [Kind] ) WHERE ([Kind] IS NOT NULL) WITH (SORT_IN_TEMPDB=ON, MAXDOP = 0)
GO

IF  EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_ID(N'[EMDR].[T_EMPR]') AND name = N'ix_EMPR_RegistrationDate')
DROP INDEX [ix_EMPR_RegistrationDate] ON [EMDR].[T_EMPR]
GO
CREATE INDEX [ix_EMPR_RegistrationDate] ON [EMDR].[T_EMPR] ( [RegistrationDate] ) WHERE ([RegistrationDate] IS NOT NULL) WITH (SORT_IN_TEMPDB=ON, MAXDOP = 0)
GO

IF  EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_ID(N'[EMDR].[T_EMDR_NOTICE_ASSOCIATION]') AND name = N'IX_EMDR_NOTICE_ASSOCIATION_Empr_Include')
DROP INDEX [IX_EMDR_NOTICE_ASSOCIATION_Empr_Include] ON [EMDR].[T_EMDR_NOTICE_ASSOCIATION]
GO
CREATE NONCLUSTERED INDEX [IX_EMDR_NOTICE_ASSOCIATION_Empr_Include] ON [EMDR].[T_EMDR_NOTICE_ASSOCIATION] ([Empr]) INCLUDE ([EmdrNoticeDoc]) WITH (MAXDOP = 0, SORT_IN_TEMPDB = ON)
GO

IF  EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_ID(N'[EHR].[T_EHR_RUS_S2DLJAP3QT]') AND name = N'IX_EHR_RUS_S2DLJAP3QT_EhrRusRefBooks')
DROP INDEX [IX_EHR_RUS_S2DLJAP3QT_EhrRusRefBooks] ON [EHR].[T_EHR_RUS_S2DLJAP3QT]
GO
CREATE NONCLUSTERED INDEX [IX_EHR_RUS_S2DLJAP3QT_EhrRusRefBooks] ON [EHR].[T_EHR_RUS_S2DLJAP3QT] ([CodeEHR]) INCLUDE ([EhrRusRefBooks]) WITH (MAXDOP = 0, SORT_IN_TEMPDB = ON)
GO

IF  EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_ID(N'[EMDR].[T_PATIENT]') AND name = N'IX_Patient_lot')
DROP INDEX [IX_Patient_lot] ON [EMDR].[T_PATIENT]
GO
CREATE NONCLUSTERED INDEX [IX_Patient_lot] ON [EMDR].[T_PATIENT] ([BirthDay],[Gender],[DocType],[Surname],[Name],[PatrName],[LocalID],[SNILS],[ENP],[DocNumber]) WITH (MAXDOP = 0, SORT_IN_TEMPDB = ON)
GO