问题
I have a set of SQL server jobs and I want the schedule for them to be dynamic i.e. I want the next run date to come from a table.
I have tried updating next_run_date in the sysjobschedules table and next_scheduled_run_date in sysjobactivity table but this doesn't do anything.
How would I go about this?
回答1:
I think you can use - sp_update_schedule to update the schedule.
sp_update_schedule
{ [ @schedule_id = ] schedule_id
| [ @name = ] 'schedule_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 ]
[ , [ @owner_login_name = ] 'owner_login_name' ]
[ , [ @automatic_post =] automatic_post ]
来源:https://stackoverflow.com/questions/18314573/sql-server-job-dynamic-schedule