Advertisement
Guest User

Untitled

a guest
Apr 16th, 2014
35
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.22 KB | None | 0 0
  1. Schema Table RowCount
  2. internal event_message_context 1,869,028
  3. internal operation_messages 1,500,811
  4. internal event_messages 1,500,803
  5.  
  6. USE SSISDB;
  7. SET NOCOUNT ON;
  8. IF object_id('tempdb..#DELETE_CANDIDATES') IS NOT NULL
  9. BEGIN
  10. DROP TABLE #DELETE_CANDIDATES;
  11. END;
  12.  
  13. CREATE TABLE #DELETE_CANDIDATES
  14. (
  15. operation_id bigint NOT NULL PRIMARY KEY
  16. );
  17.  
  18. DECLARE @DaysRetention int = 100;
  19. INSERT INTO
  20. #DELETE_CANDIDATES
  21. (
  22. operation_id
  23. )
  24. SELECT
  25. IO.operation_id
  26. FROM
  27. internal.operations AS IO
  28. WHERE
  29. IO.start_time < DATEADD(day, -@DaysRetention, CURRENT_TIMESTAMP);
  30.  
  31. DELETE T
  32. FROM
  33. internal.event_message_context AS T
  34. INNER JOIN
  35. #DELETE_CANDIDATES AS DC
  36. ON DC.operation_id = T.operation_id;
  37.  
  38. DELETE T
  39. FROM
  40. internal.event_messages AS T
  41. INNER JOIN
  42. #DELETE_CANDIDATES AS DC
  43. ON DC.operation_id = T.operation_id;
  44.  
  45. DELETE T
  46. FROM
  47. internal.operation_messages AS T
  48. INNER JOIN
  49. #DELETE_CANDIDATES AS DC
  50. ON DC.operation_id = T.operation_id;
  51.  
  52. -- etc
  53. -- Finally, remove the entry from operations
  54.  
  55. DELETE T
  56. FROM
  57. internal.operations AS T
  58. INNER JOIN
  59. #DELETE_CANDIDATES AS DC
  60. ON DC.operation_id = T.operation_id;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement