if exists (select * from sys.indexes i where i.[object_id] = OBJECT_ID('AKUZ.T_CARD_NOTE', 'U') and i.name = 'IX_T_CARD_NOTE_ReadyToBeSent')
	drop index IX_T_CARD_NOTE_ReadyToBeSent on AKUZ.T_CARD_NOTE;
go
CREATE NONCLUSTERED INDEX [IX_T_CARD_NOTE_ReadyToBeSent] ON [AKUZ].[T_CARD_NOTE] ([ReadyToBeSent], [EmdrDocType], [IsDelayed])
INCLUDE([CardNoteRecipient], [CdaDocument], [Descr], [Division], [DocumentNumber], [EmdrTemplate], [MedicalRecordID], [PluggableAttributes], [WhereToSend]) WITH (SORT_IN_TEMPDB = ON, FILLFACTOR = 95);
go

if exists (select* from sys.indexes i where i.[object_id] = OBJECT_ID('AKUZ.T_CARD_NOTE', 'U') and i.name = 'IX_T_CARD_NOTE_Division')
	drop index IX_T_CARD_NOTE_Division on AKUZ.T_CARD_NOTE;
go
CREATE INDEX [IX_T_CARD_NOTE_Division] ON [AKUZ].[T_CARD_NOTE] ( [Division], [EmdrDocType], [ReadyToBeSent] ) INCLUDE ( [DocumentNumber], [EmdrBaseObjectID], [WhereToSend]) WITH (SORT_IN_TEMPDB = ON, FILLFACTOR = 95);
GO

if exists (select* from sys.indexes i where i.[object_id] = OBJECT_ID('AKUZ.T_CARD_NOTE', 'U') and i.name = 'IX_T_CARD_NOTE_EmdrBaseObjectID')
	drop index IX_T_CARD_NOTE_EmdrBaseObjectID on AKUZ.T_CARD_NOTE;
go
CREATE INDEX [IX_T_CARD_NOTE_EmdrBaseObjectID] ON [AKUZ].[T_CARD_NOTE] ( [EmdrBaseObjectID], [EmdrBaseObjectVersion] ) INCLUDE ( [Deleted])  WITH (SORT_IN_TEMPDB = ON, FILLFACTOR = 95);
GO

if exists (select* from sys.indexes i where i.[object_id] = OBJECT_ID('AKUZ.T_CARD_NOTE', 'U') and i.name = 'IX_T_CARD_NOTE_NeedMoSign')
	drop index IX_T_CARD_NOTE_NeedMoSign on AKUZ.T_CARD_NOTE;
go
CREATE INDEX [IX_T_CARD_NOTE_NeedMoSign] ON [AKUZ].[T_CARD_NOTE] ( [NeedMoSign], [EmdrDocType], [IsDelayed] ) INCLUDE ( [CardNoteRecipient], [CdaDocument], [Division], [EmdrTemplate], [WhereToSend])  WITH (SORT_IN_TEMPDB = ON, FILLFACTOR = 95);
GO
