forked from chrisdamba/SQL-Server-Management-Studio
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Rhozet Archive Job Step.sql
72 lines (46 loc) · 1.33 KB
/
Rhozet Archive Job Step.sql
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
RAISERROR('Identify [WFSDB].[dbo].[TableJob] Records to Prune',-1,-1) WITH NOWAIT
SELECT [guid]
INTO #PruneIDs -- SELECT COUNT(*)
FROM [WFSDB].[dbo].[TableJob]
WHERE [lastUpdate] < DATEDIFF(d,Cast('0001-01-01' As DATE),GetDate()-30) * 864000000000
RAISERROR('',-1,-1) WITH NOWAIT
RAISERROR('',-1,-1) WITH NOWAIT
DelTaskPropertyEx:
RAISERROR('Delete [WFSDB].[dbo].[TableTaskPropertyEx]',-1,-1) WITH NOWAIT
DELETE TOP(100) -- SELECT COUNT(*)
FROM [WFSDB].[dbo].[TableTaskPropertyEx]
WHERE [referenceId] IN (
SELECT guid
FROM [WFSDB].[dbo].[TableTask]
WHERE [JobID] IN (
SELECT [guid]
FROM #PruneIDs
)
)
IF @@ROWCOUNT = 100
GOTO DelTaskPropertyEx
RAISERROR('',-1,-1) WITH NOWAIT
RAISERROR('',-1,-1) WITH NOWAIT
DelTableTask:
RAISERROR('Delete [WFSDB].[dbo].[TableTask]',-1,-1) WITH NOWAIT
DELETE TOP(100) -- SELECT COUNT(*)
FROM [WFSDB].[dbo].[TableTask]
WHERE [JobID] IN (
SELECT [guid]
FROM #PruneIDs
)
IF @@ROWCOUNT = 100
GOTO DelTableTask
RAISERROR('',-1,-1) WITH NOWAIT
RAISERROR('',-1,-1) WITH NOWAIT
DelTableJob:
RAISERROR('Delete [WFSDB].[dbo].[TableJob]',-1,-1) WITH NOWAIT
DELETE TOP (100) -- SELECT COUNT(*)
FROM [WFSDB].[dbo].[TableJob]
WHERE [guid] IN (
SELECT [guid]
FROM #PruneIDs
)
IF @@ROWCOUNT = 100
GOTO DelTableJob
DROP TABLE #PruneIDs