-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCreateMaintenanceJob.sql
79 lines (65 loc) · 1.76 KB
/
CreateMaintenanceJob.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
69
70
71
72
73
74
75
76
77
78
79
USE msdb;
GO
EXEC dbo.sp_add_job
@job_name = N'DailyMaintenance',
@enabled = 1,
@description = N'Execute maintenance of the database' ;
GO
EXEC dbo.sp_add_jobstep
@job_name = N'DailyMaintenance',
@step_name = N'execute daily maintenance',
@subsystem = N'TSQL',
@command = N'USE [wcs]
GO
EXECUTE [dbo].[sp_FrameworkDatabaseMaintenance];
GO
',
@retry_attempts = 5,
@retry_interval = 5 ;
GO
EXEC dbo.sp_add_schedule
@schedule_name = N'DailyMaintenance_wcs',
@freq_type = 4,
@freq_interval = 1,
@active_start_time = 071500 ;
GO
EXEC sp_attach_schedule
@job_name = N'DailyMaintenance',
@schedule_name = N'DailyMaintenance_wcs' ;
GO
EXEC sp_add_jobserver
@job_name = N'DailyMaintenance'
GO
/* weekly maintenance job */
USE msdb;
GO
EXEC dbo.sp_add_job
@job_name = N'WeeklyMaintenance',
@enabled = 1,
@description = N'Execute Weekly maintenance of the database' ;
GO
EXEC dbo.sp_add_jobstep
@job_name = N'WeeklyMaintenance',
@step_name = N'execute Weekly maintenance',
@subsystem = N'TSQL',
@command = N'USE [wcs]
GO
EXECUTE [dbo].[sp_FrameworkDatabaseMaintenance] @updateusage=1,@rebuildallindexesoffline=1,@updatestats=1,@dropautostats=1,@updateallstats=1
GO
',
@retry_attempts = 5,
@retry_interval = 5 ;
GO
EXEC dbo.sp_add_schedule
@schedule_name = N'WeeklyMaintenance_wcs',
@freq_type = 4,
@freq_interval = 1,
@active_start_time = 071500 ;
GO
EXEC sp_attach_schedule
@job_name = N'WeeklyMaintenance',
@schedule_name = N'WeeklyMaintenance_wcs' ;
GO
EXEC sp_add_jobserver
@job_name = N'WeeklyMaintenance'
GO