Script para Limpeza das Tabelas de Entrada e Integração

Anterior
Próximo
Feedback
Imprimir

Script para Limpeza das Tabelas de Entrada e Integração

Segue Script para limpeza das tabelas de entrada e Integração da Solução, onde TBDATABASEINPUT é a tabela de Entrada, TBINTEGRATIONNFCE é a tabela de Integração e 45 são os dias  mantidos de registros.

 

CREATE PROC [dbo].[LIMPARTBDATABASEINPUT]

        AS

 

        SET NOCOUNT ON

 

      declare @RowCount int

 

            select @RowCount = count(*) from TBDATABASEINPUT with (nolock) where status = 1 and INSERTDATE <= getdate() - 45

            WHILE (@RowCount > 0)

            BEGIN

                delete top(5000) from TBDATABASEINPUT with (rowlock) where status = 1 and INSERTDATE <= getdate() - 45

              select @RowCount = @@rowcount

                WAITFOR DELAY '00:00:05'

            END

 

 

CREATE PROC [dbo].[LIMPARINTEGRATIONNFCE]

         AS

 

        SET NOCOUNT ON

 

      declare @RowCount int

 

            select @RowCount = count(*) from TBINTEGRATIONNFCE with (nolock) where status = 1 and INSERTDATE <= getdate() - 45

            WHILE (@RowCount > 0)

            BEGIN

                delete top(5000) from TBINTEGRATIONNFCE with (rowlock) where status = 1 and INSERTDATE <= getdate() - 45

              select @RowCount = @@rowcount

                WAITFOR DELAY '00:00:05'

            END

 

É possível também programar esses Scripts para execução automática utilizando JOBs do SQL conforme o tutorial abaixo como exemplo:

 

Passo a Passo para Configuração do JOB

 

 

Voltar