更改指定作业的调度设置。
sp_update_jobschedule [@job_id =] job_id, | [@job_name =] 'job_name',
[@name =] 'name'
[, [@new_name =] 'new_name']
[, [@enabled =] enabled]
[, [@freq_type =] freq_type]
[, [@freq_interval =] freq_interval]
[, [@freq_subday_type =] freq_subday_type]
[, [@freq_subday_interval =] freq_subday_interval]
[, [@freq_relative_interval =] freq_relative_interval]
[, [@freq_recurrence_factor =] freq_recurrence_factor]
[, [@active_start_date =] active_start_date]
[, [@active_end_date =] active_end_date]
[, [@active_start_time =] active_start_time]
[, [@active_end_time =] active_end_time]
[@job_id =] job_id
是调度所属于的作业的标识号。job_id 的数据类型为 uniqueidentifier,其默认值为 NULL。
[@job_name =] 'job_name'
是调度所属于的作业的名称。各作业名称都必须是唯一的。job_name 的数据类型为 sysname,其默认值为 NULL。
说明 必须或者指定 job_id 或者指定 job_name,但不能两个都指定。
[@name =] 'name'
是要修改的调度的名称。name 的数据类型为 sysname,无默认值。
[@new_name =] 'new_name'
是调度的新名称。new_name 的数据类型为 sysname,其默认值为 NULL。
[@enabled =] enabled
指定启用 (1) 或不启用 (0) 调度。enabled 的数据类型为 tinyint,其默认值为 NULL。
[@freq_type =] freq_type
指定该作业运行的频繁程度。freq_type 的数据类型为 int,其默认值为 NULL,且可以取下列值之一。
值 | 描述 |
---|---|
1 | 一次。 |
4 | 按天。 |
8 | 按星期。 |
16 | 按月。 |
32 | 按月,相对于 freq_interval。 |
64 | 当 SQL Server代理启动时运行。 |
128 | 当计算机空闲时运行。 |
[@freq_interval =] freq_interval
指定作业在哪一天运行。freq_interval 的数据类型为 int,其默认值为 NULL。freq_interval 的值取决于 freq_type 的值。
freq_type 的值 | 对 freq_interval 的影响 |
---|---|
1(一次) | 未使用 freq_interval。 |
4(每天) | 每个 freq_interval 日。 |
8(每周) | freq_interval 是下列某个值或多个值(或 (OR) 在一起):
1 = 星期日 |
16(每月) | 每月的 freq_interval 日。 |
32(每月相对信息) | freq_interval 可以取下列值之一:
1 = 星期日 |
64(SQL Server 代理程序启动时) | 未使用 freq_interval。 |
[@freq_subday_type =] freq_subday_type
指定 freq_subday_interval 的单位。freq_subday_type 的数据类型为 int,其默认值为 NULL,且可以取下列值之一。
值 | 描述(单位) |
---|---|
0x1 | 在指定的时间。 |
0x4 | 分钟。 |
0x8 | 小时。 |
[@freq_subday_interval =] freq_subday_interval
指定作业每次执行之间的周期数,周期以 freq_subday_type 为单位。freq_subday_interval 的数据类型为 int,其默认值为 NULL。
[@freq_relative_interval =] freq_relative_interval
当 freq_interval 的值为 32(每月相对信息)时,指定每月调度作业发生的 freq_interval。freq_relative_interval 的数据类型为 int,其默认值为 NULL,且可以取下列值之一。
值 | 描述(单位) |
---|---|
1 | 第一个 |
2 | 第二个 |
4 | 第三个 |
8 | 第四个 |
16 | 最后一个 |
[@freq_recurrence_factor =] freq_recurrence_factor
指定作业各次调度执行之间的月数。freq_recurrence_factor 仅当 freq_type 为 8、16 或 32 时才使用。freq_recurrence_factor 的数据类型为 int,其默认值为 NULL。
[@active_start_date =] active_start_date
是作业可以开始执行的日期。active_start_date 的数据类型为 int,其默认值为 NULL。其值必须为 YYYYMMDD 格式。如果 active_start_date 不为 NULL,则日期必须大于或等于 19900101。
[@active_end_date =] active_end_date
是作业可以停止执行的日期。active_end_date 的数据类型为 int,其默认值为 NULL。其值必须为 YYYYMMDD 格式。
[@active_start_time =] active_start_time
是在 active_start_date 与 active_end_date 之间任何一天作业开始执行的时间。active_start_time 的数据类型为 int,其默认值为 NULL。其值必须以 HHMMSS 的格式输入。
[@active_end_time =] active_end_time
是在 active_start_date 与 active_end_date 之间任何一天作业停止执行的时间。active_end_time 的数据类型为 int,其默认值为 NULL。其值必须以 HHMMSS 的格式输入。
0(成功)或 1(失败)
sp_update_jobschedule 必须从 msdb 数据库中运行。
更新作业调度将增加作业的版本号。
执行权限默认授予 public 角色。
下例禁用 Archive Tables 作业的 Monday Archive 调度,并更改该调度的名称。
USE msdb
EXEC sp_update_jobschedule @job_name = 'Archive Tables',
@name = 'Monday Archive',
@new_name = 'Monday Archive - DEACTIVATED',
@enabled = 0