--BEGIN #USE
USE [IdentifyAudit]

IF NOT EXISTS(SELECT * FROM sys.indexes WHERE name = 'Idx_AuditEvent_UtcTimestamp_Id_EventType' AND object_id = OBJECT_ID('[#SCHEMA].[AuditEvent]'))
	BEGIN
		CREATE NONCLUSTERED INDEX [Idx_AuditEvent_UtcTimestamp_Id_EventType] ON [#SCHEMA].[AuditEvent]
		(
			[UtcTimestamp] ASC
		)
		INCLUDE ([Id], [EventType]) 
	END

--END #USE
--BEGIN #USE
USE [IdentifyAudit]


IF NOT EXISTS(SELECT * FROM sys.indexes WHERE name = 'Idx_AuditAdminSiteAuthentication_AuditEventId' AND object_id = OBJECT_ID('[#SCHEMA].[AuditAdminSiteAuthentication]'))
	BEGIN
		CREATE NONCLUSTERED INDEX [Idx_AuditAdminSiteAuthentication_AuditEventId] ON [#SCHEMA].[AuditAdminSiteAuthentication]
		(
			[AuditEventId] ASC
		)
	END

--END #USE
--BEGIN #USE
USE [IdentifyAudit]
	
IF NOT EXISTS(SELECT * FROM sys.indexes WHERE name = 'Idx_AuditAttributeServiceConnection_AuditEventId' AND object_id = OBJECT_ID('[#SCHEMA].[AuditAttributeServiceConnection]'))
	BEGIN
		CREATE NONCLUSTERED INDEX [Idx_AuditAttributeServiceConnection_AuditEventId] ON [#SCHEMA].[AuditAttributeServiceConnection]
		(
			[AuditEventId] ASC
		)
	END

--END #USE
--BEGIN #USE
USE [IdentifyAudit]

IF NOT EXISTS(SELECT * FROM sys.indexes WHERE name = 'Idx_AuditAuthenticationConnection_AuditEventId' AND object_id = OBJECT_ID('[#SCHEMA].[AuditAuthenticationConnection]'))
	BEGIN
		CREATE NONCLUSTERED INDEX [Idx_AuditAuthenticationConnection_AuditEventId] ON [#SCHEMA].[AuditAuthenticationConnection]
		(
			[AuditEventId] ASC
		)
	END

--END #USE
--BEGIN #USE
USE [IdentifyAudit]

IF NOT EXISTS(SELECT * FROM sys.indexes WHERE name = 'Idx_AuditAuthenticationContextMethodClass_AuditEventId' AND object_id = OBJECT_ID('[#SCHEMA].[AuditAuthenticationContextMethodClass]'))
	BEGIN
		CREATE NONCLUSTERED INDEX [Idx_AuditAuthenticationContextMethodClass_AuditEventId] ON [#SCHEMA].[AuditAuthenticationContextMethodClass]
		(
			[AuditEventId] ASC
		)
	END

--END #USE
--BEGIN #USE
USE [IdentifyAudit]

IF NOT EXISTS(SELECT * FROM sys.indexes WHERE name = 'Idx_AuditClaimDefinition_AuditEventId' AND object_id = OBJECT_ID('[#SCHEMA].[AuditClaimDefinition]'))
	BEGIN
		CREATE NONCLUSTERED INDEX [Idx_AuditClaimDefinition_AuditEventId] ON [#SCHEMA].[AuditClaimDefinition]
		(
			[AuditEventId] ASC
		)
	END

--END #USE
--BEGIN #USE
USE [IdentifyAudit]

IF NOT EXISTS(SELECT * FROM sys.indexes WHERE name = 'Idx_AuditClaimSet_AuditEventId' AND object_id = OBJECT_ID('[#SCHEMA].[AuditClaimSet]'))
	BEGIN
		CREATE NONCLUSTERED INDEX [Idx_AuditClaimSet_AuditEventId] ON [#SCHEMA].[AuditClaimSet]
		(
			[AuditEventId] ASC
		)
	END

--END #USE
--BEGIN #USE
USE [IdentifyAudit]

IF NOT EXISTS(SELECT * FROM sys.indexes WHERE name = 'Idx_AuditClaimsIssuance_AuditEventId' AND object_id = OBJECT_ID('[#SCHEMA].[AuditClaimsIssuance]'))
	BEGIN
		CREATE NONCLUSTERED INDEX [Idx_AuditClaimsIssuance_AuditEventId] ON [#SCHEMA].[AuditClaimsIssuance]
		(
			[AuditEventId] ASC
		)
	END

--END #USE
--BEGIN #USE
USE [IdentifyAudit]

IF NOT EXISTS(SELECT * FROM sys.indexes WHERE name = 'Idx_AuditClaimTransformation_AuditEventId' AND object_id = OBJECT_ID('[#SCHEMA].[AuditClaimTransformation]'))
	BEGIN
		CREATE NONCLUSTERED INDEX [Idx_AuditClaimTransformation_AuditEventId] ON [#SCHEMA].[AuditClaimTransformation]
		(
			[AuditEventId] ASC
		)
	END

--END #USE
--BEGIN #USE
USE [IdentifyAudit]
	
IF NOT EXISTS(SELECT * FROM sys.indexes WHERE name = 'Idx_AuditCorrelationError_AuditEventId' AND object_id = OBJECT_ID('[#SCHEMA].[AuditCorrelationError]'))
	BEGIN
		CREATE NONCLUSTERED INDEX [Idx_AuditCorrelationError_AuditEventId] ON [#SCHEMA].[AuditCorrelationError]
		(
			[AuditEventId] ASC
		)
	END

--END #USE
--BEGIN #USE
USE [IdentifyAudit]

IF NOT EXISTS(SELECT * FROM sys.indexes WHERE name = 'Idx_AuditDataStore_AuditEventId' AND object_id = OBJECT_ID('[#SCHEMA].[AuditDataStore]'))
	BEGIN
		CREATE NONCLUSTERED INDEX [Idx_AuditDataStore_AuditEventId] ON [#SCHEMA].[AuditDataStore]
		(
			[AuditEventId] ASC
		)
	END

--END #USE
--BEGIN #USE
USE [IdentifyAudit]

IF NOT EXISTS(SELECT * FROM sys.indexes WHERE name = 'Idx_AuditDiscreteClaimValueSpace_AuditEventId' AND object_id = OBJECT_ID('[#SCHEMA].[AuditDiscreteClaimValueSpace]'))
	BEGIN
		CREATE NONCLUSTERED INDEX [Idx_AuditDiscreteClaimValueSpace_AuditEventId] ON [#SCHEMA].[AuditDiscreteClaimValueSpace]
		(
			[AuditEventId] ASC
		)
	END

--END #USE
--BEGIN #USE
USE [IdentifyAudit]

IF NOT EXISTS(SELECT * FROM sys.indexes WHERE name = 'Idx_AuditGroup_AuditEventId' AND object_id = OBJECT_ID('[#SCHEMA].[AuditGroup]'))
	BEGIN
		CREATE NONCLUSTERED INDEX [Idx_AuditGroup_AuditEventId] ON [#SCHEMA].[AuditGroup]
		(
			[AuditEventId] ASC
		)
	END

--END #USE
--BEGIN #USE
USE [IdentifyAudit]

IF NOT EXISTS(SELECT * FROM sys.indexes WHERE name = 'Idx_AuditIdentityProviderConfiguration_AuditEventId' AND object_id = OBJECT_ID('[#SCHEMA].[AuditIdentityProviderConfiguration]'))
	BEGIN
		CREATE NONCLUSTERED INDEX [Idx_AuditIdentityProviderConfiguration_AuditEventId] ON [#SCHEMA].[AuditIdentityProviderConfiguration]
		(
			[AuditEventId] ASC
		)
	END

--END #USE
--BEGIN #USE
USE [IdentifyAudit]
	
IF NOT EXISTS(SELECT * FROM sys.indexes WHERE name = 'Idx_AuditIncomingAssertion_AuditEventId' AND object_id = OBJECT_ID('[#SCHEMA].[AuditIncomingAssertion]'))
	BEGIN
		CREATE NONCLUSTERED INDEX [Idx_AuditIncomingAssertion_AuditEventId] ON [#SCHEMA].[AuditIncomingAssertion]
		(
			[AuditEventId] ASC
		)
	END

--END #USE
--BEGIN #USE
USE [IdentifyAudit]

IF NOT EXISTS(SELECT * FROM sys.indexes WHERE name = 'Idx_AuditIssuedArtifact_AuditEventId' AND object_id = OBJECT_ID('[#SCHEMA].[AuditIssuedArtifact]'))
	BEGIN
		CREATE NONCLUSTERED INDEX [Idx_AuditIssuedArtifact_AuditEventId] ON [#SCHEMA].[AuditIssuedArtifact]
		(
			[AuditEventId] ASC
		)
	END

--END #USE
--BEGIN #USE
USE [IdentifyAudit]

IF NOT EXISTS(SELECT * FROM sys.indexes WHERE name = 'Idx_AuditIssuedClaim-ClaimsIssuanceId' AND object_id = OBJECT_ID('[#SCHEMA].[AuditIssuedClaim]'))
	BEGIN
		CREATE NONCLUSTERED INDEX [Idx_AuditIssuedClaim-ClaimsIssuanceId] ON [#SCHEMA].[AuditIssuedClaim]
		(
			[ClaimsIssuanceId] ASC
		)
	END

--END #USE
--BEGIN #USE
USE [IdentifyAudit]

IF NOT EXISTS(SELECT * FROM sys.indexes WHERE name = 'Idx_AuditLdapAttributeDefinition_AuditEventId' AND object_id = OBJECT_ID('[#SCHEMA].[AuditLdapAttributeDefinition]'))
	BEGIN
		CREATE NONCLUSTERED INDEX [Idx_AuditLdapAttributeDefinition_AuditEventId] ON [#SCHEMA].[AuditLdapAttributeDefinition]
		(
			[AuditEventId] ASC
		)
	END

--END #USE
--BEGIN #USE
USE [IdentifyAudit]

IF NOT EXISTS(SELECT * FROM sys.indexes WHERE name = 'Idx_AuditMassUpdateUserClaimValue_AuditEventId' AND object_id = OBJECT_ID('[#SCHEMA].[AuditMassUpdateUserClaimValue]'))
	BEGIN
		CREATE NONCLUSTERED INDEX [Idx_AuditMassUpdateUserClaimValue_AuditEventId] ON [#SCHEMA].[AuditMassUpdateUserClaimValue]
		(
			[AuditEventId] ASC
		)
	END

--END #USE
--BEGIN #USE
USE [IdentifyAudit]

IF NOT EXISTS(SELECT * FROM sys.indexes WHERE name = 'Idx_AuditOAuthAccessToken_AuditEventId' AND object_id = OBJECT_ID('[#SCHEMA].[AuditOAuthAccessToken]'))
	BEGIN
		CREATE NONCLUSTERED INDEX [Idx_AuditOAuthAccessToken_AuditEventId] ON [#SCHEMA].[AuditOAuthAccessToken]
		(
			[AuditEventId] ASC
		)
	END

--END #USE
--BEGIN #USE
USE [IdentifyAudit]

IF NOT EXISTS(SELECT * FROM sys.indexes WHERE name = 'Idx_AuditOrganization_AuditEventId' AND object_id = OBJECT_ID('[#SCHEMA].[AuditOrganization]'))
	BEGIN
		CREATE NONCLUSTERED INDEX [Idx_AuditOrganization_AuditEventId] ON [#SCHEMA].[AuditOrganization]
		(
			[AuditEventId] ASC
		)
	END

--END #USE
--BEGIN #USE
USE [IdentifyAudit]

IF NOT EXISTS(SELECT * FROM sys.indexes WHERE name = 'Idx_AuditPersistentPseudonym_AuditEventId' AND object_id = OBJECT_ID('[#SCHEMA].[AuditPersistentPseudonym]'))
	BEGIN
		CREATE NONCLUSTERED INDEX [Idx_AuditPersistentPseudonym_AuditEventId] ON [#SCHEMA].[AuditPersistentPseudonym]
		(
			[AuditEventId] ASC
		)
	END

--END #USE
--BEGIN #USE
USE [IdentifyAudit]

IF NOT EXISTS(SELECT * FROM sys.indexes WHERE name = 'Idx_AuditPlugIn_AuditEventId' AND object_id = OBJECT_ID('[#SCHEMA].[AuditPlugIn]'))
	BEGIN
		CREATE NONCLUSTERED INDEX [Idx_AuditPlugIn_AuditEventId] ON [#SCHEMA].[AuditPlugIn]
		(
			[AuditEventId] ASC
		)
	END

--END #USE
--BEGIN #USE
USE [IdentifyAudit]

IF NOT EXISTS(SELECT * FROM sys.indexes WHERE name = 'Idx_AuditProtocolConnection_AuditEventId' AND object_id = OBJECT_ID('[#SCHEMA].[AuditProtocolConnection]'))
	BEGIN
		CREATE NONCLUSTERED INDEX [Idx_AuditProtocolConnection_AuditEventId] ON [#SCHEMA].[AuditProtocolConnection]
		(
			[AuditEventId] ASC
		)
	END

--END #USE
--BEGIN #USE
USE [IdentifyAudit]

IF NOT EXISTS(SELECT * FROM sys.indexes WHERE name = 'Idx_AuditSharedConfigurableSetting_AuditEventId' AND object_id = OBJECT_ID('[#SCHEMA].[AuditSharedConfigurableSetting]'))
	BEGIN
		CREATE NONCLUSTERED INDEX [Idx_AuditSharedConfigurableSetting_AuditEventId] ON [#SCHEMA].[AuditSharedConfigurableSetting]
		(
			[AuditEventId] ASC
		)
	END

--END #USE
--BEGIN #USE
USE [IdentifyAudit]

IF NOT EXISTS(SELECT * FROM sys.indexes WHERE name = 'Idx_AuditTombstone_AuditEventId' AND object_id = OBJECT_ID('[#SCHEMA].[AuditTombstone]'))
	BEGIN
		CREATE NONCLUSTERED INDEX [Idx_AuditTombstone_AuditEventId] ON [#SCHEMA].[AuditTombstone]
		(
			[AuditEventId] ASC
		)
	END

--END #USE
--BEGIN #USE
USE [IdentifyAudit]

IF NOT EXISTS(SELECT * FROM sys.indexes WHERE name = 'Idx_AuditUser_AuditEventId' AND object_id = OBJECT_ID('[#SCHEMA].[AuditUser]'))
	BEGIN
		CREATE NONCLUSTERED INDEX [Idx_AuditUser_AuditEventId] ON [#SCHEMA].[AuditUser]
		(
			[AuditEventId] ASC
		)
	END

--END #USE
--BEGIN #USE
USE [IdentifyAudit]

IF NOT EXISTS(SELECT * FROM sys.indexes WHERE name = 'Idx_AuditUserClaim-UserId' AND object_id = OBJECT_ID('[#SCHEMA].[AuditUserClaim]'))
	BEGIN
		CREATE NONCLUSTERED INDEX [Idx_AuditUserClaim-UserId] ON [#SCHEMA].[AuditUserClaim]
		(
			[UserId] ASC
		)
	END

--END #USE
--BEGIN #USE
USE [IdentifyAudit]

IF NOT EXISTS(SELECT * FROM sys.indexes WHERE name = 'Idx_AuditUserDeviceCookie_AuditEventId' AND object_id = OBJECT_ID('[#SCHEMA].[AuditUserDeviceCookie]'))
	BEGIN
		CREATE NONCLUSTERED INDEX [Idx_AuditUserDeviceCookie_AuditEventId] ON [#SCHEMA].[AuditUserDeviceCookie]
		(
			[AuditEventId] ASC
		)
	END

--END #USE
--BEGIN #USE
USE [IdentifyAudit]

IF NOT EXISTS(SELECT * FROM sys.indexes WHERE name = 'Idx_AuditUserRequest_AuditEventId' AND object_id = OBJECT_ID('[#SCHEMA].[AuditUserRequest]'))
	BEGIN
		CREATE NONCLUSTERED INDEX [Idx_AuditUserRequest_AuditEventId] ON [#SCHEMA].[AuditUserRequest]
		(
			[AuditEventId] ASC
		)
	END


--END #USE

--BEGIN #USE
USE [IdentifyAudit]
IF NOT EXISTS ( SELECT * FROM sys.indexes WHERE name='IX_Logs__UserId' AND object_id = OBJECT_ID(N'[#SCHEMA].[Logs]'))
	CREATE NONCLUSTERED INDEX IX_Logs__UserId ON [#SCHEMA].[Logs] (UserId) 
--END #USE

--BEGIN #USE
USE [IdentifyAudit]
IF NOT EXISTS ( SELECT * FROM sys.indexes WHERE name='IX_Logs__EventId' AND object_id = OBJECT_ID(N'[#SCHEMA].[Logs]'))
    BEGIN	
        CREATE NONCLUSTERED INDEX IX_Logs__EventId ON [#SCHEMA].[Logs] (EventId) 
    END
--END #USE

--BEGIN #USE
USE [IdentifyAudit]
IF NOT EXISTS ( SELECT * FROM sys.indexes WHERE name='IX_Logs__RequestId' AND object_id = OBJECT_ID(N'[#SCHEMA].[Logs]'))
    BEGIN	
        CREATE NONCLUSTERED INDEX IX_Logs__RequestId ON [#SCHEMA].[Logs] (RequestId) 
    END
--END #USE

--BEGIN #USE
USE [IdentifyAudit]
IF NOT EXISTS ( SELECT * FROM sys.indexes WHERE name='IXD_Logs__TimeStamp__Type__LogLevel' AND object_id = OBJECT_ID(N'[#SCHEMA].[Logs]'))
    BEGIN	
        CREATE NONCLUSTERED INDEX IXD_Logs__TimeStamp__Type__LogLevel ON [#SCHEMA].[Logs] (TimeStamp) 
        INCLUDE ([Type], [LogLevel]) 
    END
--END #USE

--BEGIN #USE
USE [IdentifyAudit]
IF NOT EXISTS ( SELECT * FROM sys.indexes WHERE name='IX_AuditConnectionClaimSets__ConnectionId' AND object_id = OBJECT_ID(N'[#SCHEMA].[AuditConnectionClaimSets]'))
	CREATE NONCLUSTERED INDEX IX_AuditConnectionClaimSets__ConnectionId ON [#SCHEMA].[AuditConnectionClaimSets] (ConnectionId) 
--END #USE

--BEGIN #USE
USE [IdentifyAudit]
IF NOT EXISTS ( SELECT * FROM sys.indexes WHERE name='IX_AuditConnectionUserConsent__ConnectionId' AND object_id = OBJECT_ID(N'[#SCHEMA].[AuditConnectionUserConsent]'))
	CREATE NONCLUSTERED INDEX IX_AuditConnectionUserConsent__ConnectionId ON [#SCHEMA].[AuditConnectionUserConsent] (ConnectionId) 
--END #USE

--BEGIN #USE
USE [IdentifyAudit]
IF NOT EXISTS ( SELECT * FROM sys.indexes WHERE name='IX_AuditConnectionUserConsent__UserId' AND object_id = OBJECT_ID(N'[#SCHEMA].[AuditConnectionUserConsent]'))
	CREATE NONCLUSTERED INDEX IX_AuditConnectionUserConsent__UserId ON [#SCHEMA].[AuditConnectionUserConsent] (UserId) 
--END #USE

--BEGIN #USE
USE [IdentifyAudit]
IF NOT EXISTS ( SELECT * FROM sys.indexes WHERE name='IX_AuditConnectionUserConsent__NonUserUniqueKey' AND object_id = OBJECT_ID(N'[#SCHEMA].[AuditConnectionUserConsent]'))
	CREATE NONCLUSTERED INDEX IX_AuditConnectionUserConsent__NonUserUniqueKey ON [#SCHEMA].[AuditConnectionUserConsent] (NonUserUniqueKey) 
--END #USE

--BEGIN #USE
USE [IdentifyAudit]
IF NOT EXISTS ( SELECT * FROM sys.indexes WHERE name='IXD_AuditUserSecondFactorCode__AuditEventId' AND object_id = OBJECT_ID(N'[#SCHEMA].[AuditUserSecondFactorCode]'))
	CREATE NONCLUSTERED INDEX IXD_AuditUserSecondFactorCode__AuditEventId ON [#SCHEMA].[AuditUserSecondFactorCode] (AuditEventId) 
--END #USE

--BEGIN #USE
USE [IdentifyAudit]
IF NOT EXISTS ( SELECT * FROM sys.indexes WHERE name='IX_AuditUserSecondFactorCode__UserId' AND object_id = OBJECT_ID(N'[#SCHEMA].[AuditUserSecondFactorCode]'))
	CREATE NONCLUSTERED INDEX IX_AuditUserSecondFactorCode__UserId ON [#SCHEMA].[AuditUserSecondFactorCode] (UserId) 
--END #USE

--BEGIN #USE
USE [IdentifyAudit]
IF NOT EXISTS ( SELECT * FROM sys.indexes WHERE name='IX_AuditUserSecondFactorCode__OtpConnectionId' AND object_id = OBJECT_ID(N'[#SCHEMA].[AuditUserSecondFactorCode]'))
	CREATE NONCLUSTERED INDEX IX_AuditUserSecondFactorCode__OtpConnectionId ON [#SCHEMA].[AuditUserSecondFactorCode] (OtpConnectionId) 
--END #USE


--BEGIN #USE
USE [IdentifyAudit]
IF NOT EXISTS ( SELECT * FROM sys.indexes WHERE name='IXD_AuditUserRestrictedActionAttempt__AuditEventId' AND object_id = OBJECT_ID(N'[#SCHEMA].[AuditUserRestrictedActionAttempt]'))
	CREATE NONCLUSTERED INDEX IXD_AuditUserRestrictedActionAttempt__AuditEventId ON [#SCHEMA].[AuditUserRestrictedActionAttempt] (AuditEventId) 
--END #USE

--BEGIN #USE
USE [IdentifyAudit]
IF NOT EXISTS ( SELECT * FROM sys.indexes WHERE name='IXD_AuditUserRestrictedActionAttempt__AuthenticationConnectionId_UserId__ActionType' AND object_id = OBJECT_ID(N'[#SCHEMA].[AuditUserRestrictedActionAttempt]'))
	CREATE NONCLUSTERED INDEX IXD_AuditUserRestrictedActionAttempt__AuthenticationConnectionId_UserId__ActionType ON [#SCHEMA].[AuditUserRestrictedActionAttempt] (AuthenticationConnectionId) INCLUDE ([UserId], [ActionType])
--END #USE

--BEGIN #USE
USE [IdentifyAudit]
IF NOT EXISTS ( SELECT * FROM sys.indexes WHERE name='IXD_AuditNonUserRestrictedActionAttempt__AuditEventId' AND object_id = OBJECT_ID(N'[#SCHEMA].[AuditNonUserRestrictedActionAttempt]'))
	CREATE NONCLUSTERED INDEX IXD_AuditNonUserRestrictedActionAttempt__AuditEventId ON [#SCHEMA].[AuditNonUserRestrictedActionAttempt] (AuditEventId) 
--END #USE

--BEGIN #USE
USE [IdentifyAudit]
IF NOT EXISTS ( SELECT * FROM sys.indexes WHERE name='IXD_AuditNonUserRestrictedActionAttempt__AuthenticationConnectionId__NonUserUniqueKey__ActionType' AND object_id = OBJECT_ID(N'[#SCHEMA].[AuditNonUserRestrictedActionAttempt]'))
	CREATE NONCLUSTERED INDEX IXD_AuditNonUserRestrictedActionAttempt__AuthenticationConnectionId__NonUserUniqueKey__ActionType ON [#SCHEMA].[AuditNonUserRestrictedActionAttempt] (AuthenticationConnectionId) INCLUDE ([NonUserUniqueKey], [ActionType])
--END #USE

--BEGIN #USE
USE [IdentifyAudit]
IF NOT EXISTS ( SELECT * FROM sys.indexes WHERE name='IXD_AuditDeviceAuthorizationResponse__AuditEventId' AND object_id = OBJECT_ID(N'[#SCHEMA].[AuditDeviceAuthorizationResponse]'))
	CREATE NONCLUSTERED INDEX IXD_AuditDeviceAuthorizationResponse__AuditEventId ON [#SCHEMA].[AuditDeviceAuthorizationResponse] (AuditEventId) 
--END #USE

--BEGIN #USE
USE [IdentifyAudit]
IF NOT EXISTS ( SELECT * FROM sys.indexes WHERE name='IXD_AuditCryptoKey__AuditEventId' AND object_id = OBJECT_ID(N'[#SCHEMA].[AuditCryptoKey]'))
	CREATE NONCLUSTERED INDEX IXD_AuditCryptoKey__AuditEventId ON [#SCHEMA].[AuditCryptoKey] (AuditEventId) 
--END #USE
