USE [TryNFeOnline]
GO

If IndexProperty(Object_Id('[dbo].[pedidoStatus]'), '_dta_index_pedidoStatus_28_375672386__K3_K4_K2', 'IndexID') Is Null
BEGIN
CREATE NONCLUSTERED INDEX [_dta_index_pedidoStatus_28_375672386__K3_K4_K2] ON [dbo].[pedidoStatus]
(
	[situacao] ASC,
	[dataHora] ASC,
	[idPedido] ASC
) WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY  = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
END
GO
If IndexProperty(Object_Id('[dbo].[pedidoStatus]'), '_dta_index_pedidoStatus_28_375672386__K3_K2_K4', 'IndexID') Is Null
BEGIN
CREATE NONCLUSTERED INDEX [_dta_index_pedidoStatus_28_375672386__K3_K2_K4] ON [dbo].[pedidoStatus]
(
	[situacao] ASC,
	[idPedido] ASC,
	[dataHora] ASC
) WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY  = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
END
GO
If IndexProperty(Object_Id('[dbo].[pedidoStatus]'), '_dta_index_pedidoStatus_28_375672386__K3_K2', 'IndexID') Is Null
BEGIN
CREATE NONCLUSTERED INDEX [_dta_index_pedidoStatus_28_375672386__K3_K2] ON [dbo].[pedidoStatus]
(
	[situacao] ASC,
	[idPedido] ASC
) WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY  = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
END
GO
If IndexProperty(Object_Id('[dbo].[PagamentoComposicao]'), '_dta_index_PagamentoComposicao_28_366624349__K3_K8_K2', 'IndexID') Is Null
BEGIN
CREATE NONCLUSTERED INDEX [_dta_index_PagamentoComposicao_28_366624349__K3_K8_K2] ON [dbo].[PagamentoComposicao]
(
	[idNumerario] ASC,
	[idnAbatimento] ASC,
	[idPagamento] ASC
) WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY  = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
END
GO
If IndexProperty(Object_Id('[dbo].[PagamentoComposicao]'), '_dta_index_PagamentoComposicao_28_366624349__K3_K2_4', 'IndexID') Is Null
BEGIN
	CREATE NONCLUSTERED INDEX [_dta_index_PagamentoComposicao_28_366624349__K3_K2_4] ON [dbo].[PagamentoComposicao]
	(
		[idNumerario] ASC,
		[idPagamento] ASC
	) INCLUDE ([valor]) WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY  = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
END
GO
If IndexProperty(Object_Id('[dbo].[PagamentoComposicao]'), '_dta_index_PagamentoComposicao_28_366624349__K2_K8_K5_K10_K3_1_4_6_7_9', 'IndexID') Is Null
BEGIN
CREATE NONCLUSTERED INDEX [_dta_index_PagamentoComposicao_28_366624349__K2_K8_K5_K10_K3_1_4_6_7_9] ON [dbo].[PagamentoComposicao]
(
	[idPagamento] ASC,
	[idnAbatimento] ASC,
	[idChequeMovimento] ASC,
	[idCartaoMovimento] ASC,
	[idNumerario] ASC
) INCLUDE ([id],[valor],[idnReceitaDespesa],[idnTroco],[idBancoMovimento]) WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY  = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
END
GO
If IndexProperty(Object_Id('[dbo].[PagamentoComposicao]'), '_dta_index_PagamentoComposicao_28_366624349__K2_K3_K8_4', 'IndexID') Is Null
BEGIN
CREATE NONCLUSTERED INDEX [_dta_index_PagamentoComposicao_28_366624349__K2_K3_K8_4] ON [dbo].[PagamentoComposicao]
(
	[idPagamento] ASC,
	[idNumerario] ASC,
	[idnAbatimento] ASC
) INCLUDE ([valor]) WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY  = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
END
GO
If IndexProperty(Object_Id('[dbo].[NFTotal]'), '_dta_index_NFTotal_27_741577680__K1_15', 'IndexID') Is Null
BEGIN
CREATE NONCLUSTERED INDEX [_dta_index_NFTotal_27_741577680__K1_15] ON [dbo].[NFTotal]
(
	[idNotaFiscal] ASC
) INCLUDE ([icmstotalnota]) WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY  = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
END
GO
If IndexProperty(Object_Id('[dbo].[nfEmitente]'), '_dta_index_nfEmitente_27_837578022__K1_K2', 'IndexID') Is Null
BEGIN
CREATE NONCLUSTERED INDEX [_dta_index_nfEmitente_27_837578022__K1_K2] ON [dbo].[nfEmitente]
(
	[idNotaFiscal] ASC,
	[idEmitente] ASC
) WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY  = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
END
GO
If IndexProperty(Object_Id('[dbo].[ProdutoNCM]'), '_dta_index_ProdutoNCM_27_681769486__K3_1_2_4_5', 'IndexID') Is Null
BEGIN
CREATE NONCLUSTERED INDEX [_dta_index_ProdutoNCM_27_681769486__K3_1_2_4_5] ON [dbo].[ProdutoNCM]
(
	[NCM] ASC
) INCLUDE ([id],[descricao],[cest],[unidadeMedida]) WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY  = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
END
GO
If IndexProperty(Object_Id('[dbo].[BancoMovimentoComposicao]'), '_dta_index_BancoMovimentoComposicao_28_1543676547__K3_K2_1', 'IndexID') Is Null
BEGIN
CREATE NONCLUSTERED INDEX [_dta_index_BancoMovimentoComposicao_28_1543676547__K3_K2_1] ON [dbo].[BancoMovimentoComposicao]
(
	[idBancoMovimento] ASC,
	[idCaixaMovimento] ASC
) INCLUDE ([id]) WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY  = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
END
GO
If IndexProperty(Object_Id('[dbo].[BancoMovimentoComposicao]'), '_dta_index_BancoMovimentoComposicao_28_1543676547__K3', 'IndexID') Is Null
BEGIN
CREATE NONCLUSTERED INDEX [_dta_index_BancoMovimentoComposicao_28_1543676547__K3] ON [dbo].[BancoMovimentoComposicao]
(
	[idBancoMovimento] ASC
) WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY  = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
END
GO
If IndexProperty(Object_Id('[dbo].[BancoMovimentoComposicao]'), '_dta_index_BancoMovimentoComposicao_28_1543676547__K3_1_2', 'IndexID') Is Null
BEGIN
CREATE NONCLUSTERED INDEX [_dta_index_BancoMovimentoComposicao_28_1543676547__K3_1_2] ON [dbo].[BancoMovimentoComposicao]
(
	[idBancoMovimento] ASC
) INCLUDE ([id],[idCaixaMovimento]) WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY  = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
END
GO
If IndexProperty(Object_Id('[dbo].[pedidoProduto]'), '_dta_index_pedidoProduto_28_503672842__K2_K1_8', 'IndexID') Is Null
BEGIN
CREATE NONCLUSTERED INDEX [_dta_index_pedidoProduto_28_503672842__K2_K1_8] ON [dbo].[pedidoProduto]
(
	[idPedido] ASC,
	[id] ASC
) INCLUDE ([vprod]) WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY  = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
END
GO
If IndexProperty(Object_Id('[dbo].[produto]'), '_dta_index_produto_28_2117582582__K1_K21_2_4_8_23', 'IndexID') Is Null
BEGIN
CREATE NONCLUSTERED INDEX [_dta_index_produto_28_2117582582__K1_K21_2_4_8_23] ON [dbo].[produto]
(
	[id] ASC,
	[idnBaixa] ASC
) INCLUDE ([descricao],[cean],[ucom],[refFabrica]) WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY  = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
END
GO
If IndexProperty(Object_Id('[dbo].[pedidoProduto]'), '_dta_index_pedidoProduto_28_503672842__K2_K1_8_12_20', 'IndexID') Is Null
BEGIN
CREATE NONCLUSTERED INDEX [_dta_index_pedidoProduto_28_503672842__K2_K1_8_12_20] ON [dbo].[pedidoProduto]
(
	[idPedido] ASC,
	[id] ASC
) INCLUDE ([vprod],[vDesc],[totalCusto]) WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY  = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
END
GO
If IndexProperty(Object_Id('[dbo].[FaturaParcela]'), '_dta_index_FaturaParcela_27_302624121__K6_K4_K2_1_3_5_7_8_9_10_11_12_13_14_15_16_17_18', 'IndexID') Is Null
BEGIN
CREATE NONCLUSTERED INDEX [_dta_index_FaturaParcela_27_302624121__K6_K4_K2_1_3_5_7_8_9_10_11_12_13_14_15_16_17_18] ON [dbo].[FaturaParcela]
(
	[saldo] ASC,
	[dataVencimento] ASC,
	[idFatura] ASC
) INCLUDE ([id],[observacao],[saldoAnteriorBaixa],[parcela],[valor],[idnQuitada],[saldoJuro],[valorMulta],[dataCalculoJuro],[numeroDuplicata],[idnBaixado],[dataBaixa],[idFaturaAgrupada],[saldoAnteriorAgrupamento],[percentualJuro]) WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY  = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
END
GO
If IndexProperty(Object_Id('[dbo].[FaturaParcela]'), '_dta_index_FaturaParcela_27_302624121__K1_K2', 'IndexID') Is Null
BEGIN
CREATE NONCLUSTERED INDEX [_dta_index_FaturaParcela_27_302624121__K1_K2] ON [dbo].[FaturaParcela]
(
	[id] ASC,
	[idFatura] ASC
) WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY  = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
END
GO
If IndexProperty(Object_Id('[dbo].[pedidoProduto]'), '_dta_index_pedidoProduto_28_503672842__K2_K1_K15', 'IndexID') Is Null
BEGIN
CREATE NONCLUSTERED INDEX [_dta_index_pedidoProduto_28_503672842__K2_K1_K15] ON [dbo].[pedidoProduto]
(
	[idPedido] ASC,
	[id] ASC,
	[idnImpresso] ASC
) WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY  = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
END
GO
If IndexProperty(Object_Id('[dbo].[Fatura]'), '_dta_index_Fatura_27_46623209__K16_K1_K12_K26_K31_K32_K33_K37', 'IndexID') Is Null
BEGIN
CREATE NONCLUSTERED INDEX [_dta_index_Fatura_27_46623209__K16_K1_K12_K26_K31_K32_K33_K37] ON [dbo].[Fatura]
(
	[idnReceitaDespesa] ASC,
	[id] ASC,
	[idEmitente] ASC,
	[idnTransferencia] ASC,
	[idnSaque] ASC,
	[idnDeposito] ASC,
	[idnTransferenciaEntreContas] ASC,
	[idnTrocaNumerario] ASC
) WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY  = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
END
GO
If IndexProperty(Object_Id('[dbo].[Fatura]'), '_dta_index_Fatura_27_46623209__K12_K16_K31_K32_K33_K37_K26_K1', 'IndexID') Is Null
BEGIN
CREATE NONCLUSTERED INDEX [_dta_index_Fatura_27_46623209__K12_K16_K31_K32_K33_K37_K26_K1] ON [dbo].[Fatura]
(
	[idEmitente] ASC,
	[idnReceitaDespesa] ASC,
	[idnSaque] ASC,
	[idnDeposito] ASC,
	[idnTransferenciaEntreContas] ASC,
	[idnTrocaNumerario] ASC,
	[idnTransferencia] ASC,
	[id] ASC
) WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY  = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
END
GO
If IndexProperty(Object_Id('[dbo].[Fatura]'), '_dta_index_Fatura_27_46623209__K1_K12_K31_K32_K33_K37_K36_K26', 'IndexID') Is Null
BEGIN
CREATE NONCLUSTERED INDEX [_dta_index_Fatura_27_46623209__K1_K12_K31_K32_K33_K37_K36_K26] ON [dbo].[Fatura]
(
	[id] ASC,
	[idEmitente] ASC,
	[idnSaque] ASC,
	[idnDeposito] ASC,
	[idnTransferenciaEntreContas] ASC,
	[idnTrocaNumerario] ASC,
	[idnLancamentoCartao] ASC,
	[idnTransferencia] ASC
) WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY  = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
END
GO
If IndexProperty(Object_Id('[dbo].[BancoMovimento]'), '_dta_index_BancoMovimento_27_1819153526__K5_K1_K3_2_4_6_7_8_9_10_11_12_13_14_15_16_17', 'IndexID') Is Null
BEGIN
CREATE NONCLUSTERED INDEX [_dta_index_BancoMovimento_27_1819153526__K5_K1_K3_2_4_6_7_8_9_10_11_12_13_14_15_16_17] ON [dbo].[BancoMovimento]
(
	[idConta] ASC,
	[id] ASC,
	[data] ASC
) INCLUDE ([idnDeposito],[tipoDC],[idCaixaMovimento],[dataProvComp],[historico],[valor],[idCartaoLote],[idChequeEmitido],[nomeArquivoRetorno],[numDocto],[portador],[dataConciliacao],[idnCheque],[idnDepositoNaoIdentificado]) WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY  = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
END
GO
If IndexProperty(Object_Id('[dbo].[BancoMovimento]'), '_dta_index_BancoMovimento_27_1819153526__K14_K1_2_3_4_5_6_7_8_9_10_11_12_13_15_16_17', 'IndexID') Is Null
BEGIN
CREATE NONCLUSTERED INDEX [_dta_index_BancoMovimento_27_1819153526__K14_K1_2_3_4_5_6_7_8_9_10_11_12_13_15_16_17] ON [dbo].[BancoMovimento]
(
	[dataConciliacao] ASC,
	[id] ASC
) INCLUDE ([idnDeposito],[tipoDC],[idCaixaMovimento],[data],[dataProvComp],[idConta],[historico],[valor],[idCartaoLote],[idnDepositoNaoIdentificado],[nomeArquivoRetorno],[numDocto],[portador],[idnCheque],[idChequeEmitido]) WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY  = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
END
GO
If IndexProperty(Object_Id('[dbo].[Fatura]'), '_dta_index_Fatura_28_46623209__K1_13', 'IndexID') Is Null
BEGIN
CREATE NONCLUSTERED INDEX [_dta_index_Fatura_28_46623209__K1_13] ON [dbo].[Fatura]
(
	[id] ASC
) INCLUDE ([idReceitaDespesa]) WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY  = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
END
GO
If IndexProperty(Object_Id('[dbo].[pedido]'), '_dta_index_pedido_28_1598628738__K19_K26_K6_K7_K3_K10_K4_K5_K15_K14_K18_K30_K11_K28_K2_K1', 'IndexID') Is Null
BEGIN
CREATE NONCLUSTERED INDEX [_dta_index_pedido_28_1598628738__K19_K26_K6_K7_K3_K10_K4_K5_K15_K14_K18_K30_K11_K28_K2_K1] ON [dbo].[pedido]
(
	[idnPreVendaComanda] ASC,
	[idnPedidoDelivery] ASC,
	[dataPedido] ASC,
	[dataEntrega] ASC,
	[idEmitente] ASC,
	[idOperacao] ASC,
	[idParceiro] ASC,
	[idParceiroVendedor] ASC,
	[idnCancelado] ASC,
	[idnFaturado] ASC,
	[idnProducao] ASC,
	[idnExpedicao] ASC,
	[tipoPedido] ASC,
	[idRepresentante] ASC,
	[numeroPedido] ASC,
	[id] ASC
) WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY  = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
END
GO
If IndexProperty(Object_Id('[dbo].[pedido]'), '_dta_index_pedido_28_1598628738__K11_K1_K28_K4_K5', 'IndexID') Is Null
BEGIN
CREATE NONCLUSTERED INDEX [_dta_index_pedido_28_1598628738__K11_K1_K28_K4_K5] ON [dbo].[pedido]
(
	[tipoPedido] ASC,
	[id] ASC,
	[idRepresentante] ASC,
	[idParceiro] ASC,
	[idParceiroVendedor] ASC
) WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY  = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
END
GO
If IndexProperty(Object_Id('[dbo].[pedido]'), '_dta_index_pedido_28_1598628738__K11_K1_K28_K4', 'IndexID') Is Null
BEGIN
CREATE NONCLUSTERED INDEX [_dta_index_pedido_28_1598628738__K11_K1_K28_K4] ON [dbo].[pedido]
(
	[tipoPedido] ASC,
	[id] ASC,
	[idRepresentante] ASC,
	[idParceiro] ASC
) WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY  = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
END
GO
If IndexProperty(Object_Id('[dbo].[parceiro]'), '_dta_index_parceiro_28_1117247035__K2_K14_1', 'IndexID') Is Null
BEGIN
CREATE NONCLUSTERED INDEX [_dta_index_parceiro_28_1117247035__K2_K14_1] ON [dbo].[parceiro]
(
	[razaosocial] ASC,
	[idCidade] ASC
) INCLUDE ([id]) WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY  = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
END
GO
If IndexProperty(Object_Id('[dbo].[parceiro]'), '_dta_index_parceiro_28_1117247035__K2_K1', 'IndexID') Is Null
BEGIN
CREATE NONCLUSTERED INDEX [_dta_index_parceiro_28_1117247035__K2_K1] ON [dbo].[parceiro]
(
	[razaosocial] ASC,
	[id] ASC
) WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY  = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
END
GO
If IndexProperty(Object_Id('[dbo].[parceiro]'), '_dta_index_parceiro_28_1117247035__K1_K2', 'IndexID') Is Null
BEGIN
CREATE NONCLUSTERED INDEX [_dta_index_parceiro_28_1117247035__K1_K2] ON [dbo].[parceiro]
(
	[id] ASC,
	[razaosocial] ASC
) WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY  = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
END
GO
If IndexProperty(Object_Id('[dbo].[CaixaMovimento]'), '_dta_index_CaixaMovimento_28_478624748__K2_9', 'IndexID') Is Null
BEGIN
CREATE NONCLUSTERED INDEX [_dta_index_CaixaMovimento_28_478624748__K2_9] ON [dbo].[CaixaMovimento]
(
	[idCaixa] ASC
) INCLUDE ([idFaturaParcelaPagamentoOrigem]) WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY  = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
END
GO
If IndexProperty(Object_Id('[dbo].[notafiscal]'), '_dta_index_notafiscal_28_613577224__K23_K7_K25_K5_K141_K1_K38', 'IndexID') Is Null
BEGIN
CREATE NONCLUSTERED INDEX [_dta_index_notafiscal_28_613577224__K23_K7_K25_K5_K141_K1_K38] ON [dbo].[notafiscal]
(
	[nfeTpAmb] ASC,
	[tipodocumento] ASC,
	[nfeCstat] ASC,
	[dataEmissao] ASC,
	[dataEmissaoNotaFiscal] ASC,
	[id] ASC,
	[idOperacao] ASC
) WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY  = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
END
GO
If IndexProperty(Object_Id('[dbo].[CaixaMovimento]'), '_dta_index_CaixaMovimento_27_478624748__K1_K7', 'IndexID') Is Null
BEGIN
CREATE NONCLUSTERED INDEX [_dta_index_CaixaMovimento_27_478624748__K1_K7] ON [dbo].[CaixaMovimento]
(
	[id] ASC,
	[tipoDC] ASC
) WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY  = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
END
GO
If IndexProperty(Object_Id('[dbo].[notafiscal]'), '_dta_index_notafiscal_28_613577224__K7_K1_K38_K25_K23_K5_K77_141', 'IndexID') Is Null
BEGIN
CREATE NONCLUSTERED INDEX [_dta_index_notafiscal_28_613577224__K7_K1_K38_K25_K23_K5_K77_141] ON [dbo].[notafiscal]
(
	[tipodocumento] ASC,
	[id] ASC,
	[idOperacao] ASC,
	[nfeCstat] ASC,
	[nfeTpAmb] ASC,
	[dataEmissao] ASC,
	[numeroMovimento] ASC
) INCLUDE ([dataEmissaoNotaFiscal]) WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY  = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
END
GO
If IndexProperty(Object_Id('[dbo].[CaixaMovimento]'), '_dta_index_CaixaMovimento_28_478624748__K2_1_3_4_5_6_7_8_9_10_11_12_13_14_15_16_17', 'IndexID') Is Null
BEGIN
CREATE NONCLUSTERED INDEX [_dta_index_CaixaMovimento_28_478624748__K2_1_3_4_5_6_7_8_9_10_11_12_13_14_15_16_17] ON [dbo].[CaixaMovimento]
(
	[idCaixa] ASC
) INCLUDE ([id],[idCaixaMovimentoEstornado],[dataHora],[operacaoCaixa],[historico],[valor],[tipoDC],[idOperadorMovimentacao],[idFaturaParcelaPagamentoOrigem],[idChequeEmitidoMovimento],[totalDinheiro],[totalChequeTerc],[totalDeposito],[totalRecebimento],[totalPagamento],[dataHoraCriacao]) WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY  = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
END
GO
If IndexProperty(Object_Id('[dbo].[notafiscal]'), '_dta_index_notafiscal_27_613577224__K38_K5_K141_K7_K25_K23_K1', 'IndexID') Is Null
BEGIN
CREATE NONCLUSTERED INDEX [_dta_index_notafiscal_27_613577224__K38_K5_K141_K7_K25_K23_K1] ON [dbo].[notafiscal]
(
	[idOperacao] ASC,
	[dataEmissao] ASC,
	[dataEmissaoNotaFiscal] ASC,
	[tipodocumento] ASC,
	[nfeCstat] ASC,
	[nfeTpAmb] ASC,
	[id] ASC
) WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY  = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
END
GO
If IndexProperty(Object_Id('[dbo].[notafiscal]'), '_dta_index_notafiscal_27_613577224__K23_K25_K158_K5_K141_K1', 'IndexID') Is Null
BEGIN
CREATE NONCLUSTERED INDEX [_dta_index_notafiscal_27_613577224__K23_K25_K158_K5_K141_K1] ON [dbo].[notafiscal]
(
	[nfeTpAmb] ASC,
	[nfeCstat] ASC,
	[idnInutilizado] ASC,
	[dataEmissao] ASC,
	[dataEmissaoNotaFiscal] ASC,
	[id] ASC
) WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY  = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
END
GO
If IndexProperty(Object_Id('[dbo].[notafiscal]'), '_dta_index_notafiscal_27_613577224__K191_K79_K157_K82_K83_K37_K128_K69_K40_K165_K109_K25_K1', 'IndexID') Is Null
BEGIN
CREATE NONCLUSTERED INDEX [_dta_index_notafiscal_27_613577224__K191_K79_K157_K82_K83_K37_K128_K69_K40_K165_K109_K25_K1] ON [dbo].[notafiscal]
(
	[terminalServerSessionName] ASC,
	[idnDocumentoEmitido] ASC,
	[dataAtualizacaoStatusNota] ASC,
	[idOperador] ASC,
	[nomeComputadorEmissao] ASC,
	[idnImpresso] ASC,
	[idnEmiteNFCe] ASC,
	[idnEmiteCte] ASC,
	[idnEmiteNF] ASC,
	[idnEmiteCTeOS] ASC,
	[idnEmiteMDFe] ASC,
	[nfeCstat] ASC,
	[id] ASC
) WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY  = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
END
GO
If IndexProperty(Object_Id('[dbo].[CaixaMovimento]'), '_dta_index_CaixaMovimento_27_478624748__K7', 'IndexID') Is Null
BEGIN
CREATE NONCLUSTERED INDEX [_dta_index_CaixaMovimento_27_478624748__K7] ON [dbo].[CaixaMovimento]
(
	[tipoDC] ASC
) WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY  = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
END
GO
If IndexProperty(Object_Id('[dbo].[CaixaMovimento]'), '_dta_index_CaixaMovimento_27_478624748__K9_K3_1_2_4_5_6_7_8_10_11_12_13_14_15_16_17', 'IndexID') Is Null
BEGIN
CREATE NONCLUSTERED INDEX [_dta_index_CaixaMovimento_27_478624748__K9_K3_1_2_4_5_6_7_8_10_11_12_13_14_15_16_17] ON [dbo].[CaixaMovimento]
(
	[idFaturaParcelaPagamentoOrigem] ASC,
	[dataHora] ASC
) INCLUDE ([id],[idCaixaMovimentoEstornado],[idCaixa],[operacaoCaixa],[historico],[valor],[tipoDC],[idOperadorMovimentacao],[idChequeEmitidoMovimento],[totalDinheiro],[totalChequeTerc],[totalDeposito],[totalRecebimento],[totalPagamento],[dataHoraCriacao]) WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY  = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
END
GO
If IndexProperty(Object_Id('[dbo].[MDeConsultaNFe]'), '_dta_index_MDeConsultaNFe_27_288720081__K1_K2_K20', 'IndexID') Is Null
BEGIN
CREATE NONCLUSTERED INDEX [_dta_index_MDeConsultaNFe_27_288720081__K1_K2_K20] ON [dbo].[MDeConsultaNFe]
(
	[id] ASC,
	[tpAmb] ASC,
	[idnNovoWS] ASC
) WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY  = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
END
GO
If IndexProperty(Object_Id('[dbo].[FaturaParcelaPagamento]'), '_dta_index_FaturaParcelaPagamento_28_270624007__K3_K1_2_4_5_6_7_8_9_10_11_12', 'IndexID') Is Null
BEGIN
CREATE NONCLUSTERED INDEX [_dta_index_FaturaParcelaPagamento_28_270624007__K3_K1_2_4_5_6_7_8_9_10_11_12] ON [dbo].[FaturaParcelaPagamento]
(
	[idPagamento] ASC,
	[id] ASC
) INCLUDE ([idFaturaParcela],[valor],[saldoCapitalAnterior],[saldoJuroAnterior],[valorCapital],[valorJuro],[valorMulta],[valorDesconto],[valorDescontoAdiantamento],[valorOutros]) WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY  = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
END
GO
If IndexProperty(Object_Id('[dbo].[FaturaParcelaPagamento]'), '_dta_index_FaturaParcelaPagamento_27_270624007__K1_K2', 'IndexID') Is Null
BEGIN
CREATE NONCLUSTERED INDEX [_dta_index_FaturaParcelaPagamento_27_270624007__K1_K2] ON [dbo].[FaturaParcelaPagamento]
(
	[id] ASC,
	[idFaturaParcela] ASC
) WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY  = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
END
GO
If IndexProperty(Object_Id('[dbo].[cidade]'), '_dta_index_cidade_28_549576996__K6', 'IndexID') Is Null
BEGIN
CREATE NONCLUSTERED INDEX [_dta_index_cidade_28_549576996__K6] ON [dbo].[cidade]
(
	[uf] ASC
) WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY  = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
END
GO
If IndexProperty(Object_Id('[dbo].[cidade]'), '_dta_index_cidade_28_549576996__K1_K6', 'IndexID') Is Null
BEGIN
CREATE NONCLUSTERED INDEX [_dta_index_cidade_28_549576996__K1_K6] ON [dbo].[cidade]
(
	[id] ASC,
	[uf] ASC
) WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY  = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
END
GO
If IndexProperty(Object_Id('[dbo].[cidade]'), '_dta_index_cidade_28_549576996__K1', 'IndexID') Is Null
BEGIN
CREATE NONCLUSTERED INDEX [_dta_index_cidade_28_549576996__K1] ON [dbo].[cidade]
(
	[id] ASC
) WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY  = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
END
GO
If IndexProperty(Object_Id('[dbo].[Caixa]'), '_dta_index_Caixa_28_510624862__K5_K3_K2_K4_K1', 'IndexID') Is Null
BEGIN
CREATE NONCLUSTERED INDEX [_dta_index_Caixa_28_510624862__K5_K3_K2_K4_K1] ON [dbo].[Caixa]
(
	[sequencia] ASC,
	[idEmitente] ASC,
	[idOperador] ASC,
	[data] ASC,
	[id] ASC
) WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY  = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
END
GO
declare @diasSemManutencao int = 0;
SET @diasSemManutencao = (select DATEDIFF(DAY,coalesce(m.dataUltimaExecucao, DATEADD(week,-2, getdate())), GETDATE()) from ManutencoesBanco m where descricao = 'INDICES');
if (@diasSemManutencao >= 7)
begin
	EXEC sp_msforeachtable 'SET QUOTED_IDENTIFIER ON ALTER INDEX ALL ON ? REBUILD WITH (FILLFACTOR = 90)';
	EXEC sp_msforeachtable 'SET QUOTED_IDENTIFIER ON ALTER INDEX ALL ON ? REORGANIZE';
	UPDATE ManutencoesBanco set dataUltimaExecucao = GETDATE() where descricao = 'INDICES';
end;
GO
INSERT INTO VERSAO(VERSAO, VERSAOATUALIZACAO, DATAATUALIZACAO) VALUES(431, 689, GETDATE());