Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Code Block
languagesql
DECLARE @DeleteBefore DATETIME = CAST('2000-12-31T00:00:00' AS DATETIME)

DELETE FROM Contexts WHERE ContextType = 'ElementContext' AND FlowContextId IN (SELECT Id FROM Contexts WHERE FlowContextIdContextType IS= NULL'FlowContext' AND CreateTime < @DeleteBefore);
DELETE FROM ContextIndices WHERE FlowContextId IN (SELECT Id FROM Contexts WHERE FlowContextIdContextType IS= NULL'FlowContext' AND CreateTime < @DeleteBefore);
DELETE FROM ContextLogs WHERE FlowContextId IN (SELECT Id FROM Contexts WHERE FlowContextIdContextType IS= NULL'FlowContext' AND CreateTime < @DeleteBefore);
DELETE FROM Contexts WHERE FlowContextIdContextType IS= NULL'FlowContext' AND CreateTime < @DeleteBefore;
DELETE FROM PerformanceRecords WHERE [Time] < @DeleteBefore;

DBCC INDEXDEFRAG(0, 'Contexts')
DBCC INDEXDEFRAG(0, 'ContextIndices')
DBCC INDEXDEFRAG(0, 'ContextLogs')
DBCC INDEXDEFRAG(0, 'PerformanceRecords')

Sollen alle Kontexte und Leistungsdatensätze gelöschte werden, kann dieser Vorgang durch die Verwendung von TRUNCATE beschleunigt werden:

Code Block
languagesql
TRUNCATE TABLE Contexts;
TRUNCATE TABLE ContextLogs;
TRUNCATE TABLE ContextIndices;
TRUNCATE TABLE PerformanceRecords;

DBCC INDEXDEFRAG(0, 'Contexts')
DBCC INDEXDEFRAG(0, 'ContextIndices')
DBCC INDEXDEFRAG(0, 'ContextLogs')
DBCC INDEXDEFRAG(0, 'PerformanceRecords')

Verkleinern der Datenbank

Das Löschen einer großen Menge an Daten führt nicht unbedingt dazu, dass auch die Größe der Datenbank abnimmt. In diesem Fall empfiehlt es sich, die Datenbank anzuweisen, den nicht mehr benötigten Platz wieder freizugeben. Dies lässt sich mit folgendem SQL-Skript erreichen:

Code Block
languagesql
DBCC SHRINKDATABASE(0, 10) WITH WAIT_AT_LOW_PRIORITY (ABORT_AFTER_WAIT = SELF)

...