IF NOT EXISTS ( SELECT * FROM sysindexes ix WHERE  ix.name = 'idx_channel_set_id_channel_set_channel')
BEGIN
	CREATE INDEX idx_channel_set_id_channel_set_channel
	ON NB_ChannelSetChannel
	(
		ChannelSetID
	)
END
GO

IF NOT EXISTS ( SELECT * FROM sysindexes ix WHERE  ix.name = 'idx_O365GroupId_BA_Site')
BEGIN
	CREATE INDEX idx_O365GroupId_BA_Site
	ON BA_Site
	(
		O365GroupId
	)
END
GO

IF NOT EXISTS ( SELECT * FROM sysindexes ix WHERE  ix.name = 'idx_SharePointWebId_BA_Site')
BEGIN
	CREATE INDEX idx_SharePointWebId_BA_Site
	ON BA_Site
	(
		SharePointWebId
	)
END
GO


IF NOT EXISTS ( SELECT * FROM sysindexes ix WHERE  ix.name = 'idx_SitecollectionID_SiteCollectionTaskQueue')
BEGIN
	CREATE INDEX idx_SitecollectionID_SiteCollectionTaskQueue
	ON SiteCollectionTaskQueue
	(
		SitecollectionID
	)
END
GO

IF NOT EXISTS ( SELECT * FROM sysindexes ix WHERE  ix.name = 'idx_Status_SiteCollectionTaskQueue')
BEGIN
	CREATE INDEX idx_Status_SiteCollectionTaskQueue
	ON SiteCollectionTaskQueue
	(
		Status
	)
END
GO

IF NOT EXISTS ( SELECT * FROM sysindexes ix WHERE  ix.name = 'idx_Started_SiteCollectionTaskQueue')
BEGIN
	CREATE INDEX idx_Started_SiteCollectionTaskQueue
	ON SiteCollectionTaskQueue
	(
		Started
	)
END
GO

IF NOT EXISTS ( SELECT * FROM sysindexes ix WHERE  ix.name = 'idx_Started_BA_MetadataDefinition')
BEGIN
	CREATE INDEX idx_Started_BA_MetadataDefinition
	ON BA_MetadataDefinition
	(
		Name
	)
END
GO

IF NOT EXISTS ( SELECT * FROM sysindexes ix WHERE  ix.name = 'idx_TargetID_Comment')
BEGIN
	CREATE INDEX idx_TargetID_Comment
	ON Comment
	(
		TargetID
	)							
END
GO

IF NOT EXISTS ( SELECT * FROM sysindexes ix WHERE  ix.name = 'idx_TargetType_Comment')
BEGIN
	CREATE INDEX idx_TargetType_Comment
	ON Comment
	(
		TargetType
	)
END
GO

IF NOT EXISTS ( SELECT * FROM sysindexes ix WHERE  ix.name = 'idx_TaskType_SiteCollectionTaskQueue')
BEGIN
	CREATE INDEX idx_TaskType_SiteCollectionTaskQueue
	ON SiteCollectionTaskQueue
	(
		TaskType
	)
END
GO

IF NOT EXISTS ( SELECT * FROM sysindexes ix WHERE  ix.name = 'idx_Groups_PrincipalID_PrincipalGrouping')
BEGIN
	CREATE INDEX idx_Groups_PrincipalID_PrincipalGrouping
	ON PrincipalGrouping
	(
		Groups_PrincipalID
	)
END
GO

IF NOT EXISTS ( SELECT * FROM sysindexes ix WHERE  ix.name = 'idx_Members_PrincipalID_PrincipalGrouping')
BEGIN
	CREATE INDEX idx_Members_PrincipalID_PrincipalGrouping
	ON PrincipalGrouping
	(
		Members_PrincipalID
	)
END
GO

IF NOT EXISTS ( SELECT * FROM sysindexes ix WHERE  ix.name = 'idx_PrincipalID_NB_ChannelSetChannel')
BEGIN
	CREATE INDEX idx_PrincipalID_NB_ChannelSetChannel
	ON NB_ChannelSetChannel
	(
		PrincipalID
	)
END
GO

IF NOT EXISTS ( SELECT * FROM sysindexes ix WHERE  ix.name = 'idx_Type_NB_ChannelSetChannel')
BEGIN
	CREATE INDEX idx_Type_NB_ChannelSetChannel
	ON NB_ChannelSetChannel
	(
		Type
	)
END
GO

IF NOT EXISTS ( SELECT * FROM sysindexes ix WHERE  ix.name = 'PK_NB_ITEM_Tags')
BEGIN
	CREATE CLUSTERED INDEX PK_NB_ITEM_Tags 
	ON NB_ITEM_TAGS
	(
		NB_Item_ItemID
	)
END
GO

IF NOT EXISTS ( SELECT * FROM sysindexes ix WHERE  ix.name = 'idx_NB_TAGS_TERM_ID_NB_ITEM_Tags')
BEGIN
	CREATE INDEX idx_NB_TAGS_TERM_ID_NB_ITEM_Tags 
	ON NB_ITEM_TAGS
	(
		NB_Tags_TermId
	)
END
GO

IF NOT EXISTS ( SELECT * FROM sysindexes ix WHERE  ix.name = 'idx_AuthorId_Comment')
BEGIN
	CREATE INDEX idx_AuthorId_Comment
	ON Comment
	(
		AuthorId
	)
END
GO


 IF NOT EXISTS ( SELECT * FROM sysindexes ix WHERE  ix.name = 'nci_wi_NB_ChannelSetID_PrincipalID_ChannelSetChannel')
 BEGIN
 	CREATE NONCLUSTERED INDEX [nci_wi_NB_ChannelSetID_PrincipalID_ChannelSetChannel] ON [dbo].[NB_ChannelSetChannel] ([ChannelSetID], [PrincipalID]) INCLUDE ([PermissionChannel])
 END
 GO

 IF NOT EXISTS ( SELECT * FROM sysindexes ix WHERE  ix.name = 'nci_wi_GroupId_Principal')
 BEGIN
 	CREATE NONCLUSTERED INDEX [nci_wi_GroupId_Principal] ON [dbo].[Principal] ([GroupId]) INCLUDE ([ADId])
 END
 GO

 IF NOT EXISTS ( SELECT * FROM sysindexes ix WHERE  ix.name = 'nci_wi_Type_Principal')
 BEGIN
 	CREATE NONCLUSTERED INDEX [nci_wi_Type_Principal] ON [dbo].[Principal] ([Type])
 END
 GO

 IF NOT EXISTS ( SELECT * FROM sysindexes ix WHERE  ix.name = 'nci_wi_LastActive_Principal')
 BEGIN
 	CREATE NONCLUSTERED INDEX [nci_wi_LastActive_Principal] ON [dbo].[Principal] ([LastActive]) INCLUDE ([LoginName])
 END
 GO
