USE [TryNFeOnline]
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(426, 684, GETDATE());