This commit is contained in:
Thierry Schork
2025-07-09 16:43:53 +02:00
parent b9cfbda6dc
commit 1975962f2d
9 changed files with 322 additions and 7 deletions

View File

@@ -0,0 +1,28 @@
USE [DocumedisUsageLogs]
GO
/*
MDDOC-878
Purge of the table DocumedisUsageLogs.dbo.Documedis2020UsageLogs
Records that are more than 7 months old will be purged.
Deletion is made in batches to avoid locking.
*/
CREATE PROCEDURE [purge_Documedis2020UsageLogs]
AS
BEGIN
DECLARE @cutoff DATE = DATEADD(MONTH, -7, CURRENT_TIMESTAMP);
DECLARE @batch INT = 5000;
DECLARE @row_count INT = 1;
WHILE @row_count > 0
BEGIN
DELETE TOP(@batch) s
FROM [dbo].[Documedis2020UsageLogs] s
WHERE [s].[LogDateTime] > @cutoff;
SET @row_count = @@rowcount;
END
END