sp_delete_schedule

sp_delete_schedule#

Deletes a schedule.

Syntax#

sp_delete_schedule { [ @schedule_id = ] schedule_id | [ @schedule_name = ] 'schedule_name' } ,
  [ @force_delete = ] force_delete

Arguments#

[ @schedule_id = ] schedule_id

The schedule identification number of the schedule to delete. schedule_id is int, with a default of NULL.

Note

Either schedule_id or schedule_name must be specified, but both cannot be specified.

[ @schedule_name = ] ‘schedule_name’

The name of the schedule to delete. schedule_name is sysname, with a default of NULL.

Either schedule_id or schedule_name must be specified, but both cannot be specified.

[ @force_delete = ] force_delete

Specifies whether the procedure should fail if the schedule is attached to a job. Force_delete is bit, with a default of 0. When force_delete is 0, the stored procedure fails if the schedule is attached to a job. When force_delete is 1, the schedule is deleted regardless of whether the schedule is attached to a job.

Result Sets#

None

Remarks#

By default, a schedule cannot be deleted if the schedule is attached to a job. To delete a schedule that is attached to a job, specify a value of 1 for force_delete. Deleting a schedule does not stop jobs that are currently running.

Permissions#

By default, members of the sysadmin fixed server role can execute this stored procedure.

Note that the job owner can attach a job to a schedule and detach a job from a schedule without also having to be the schedule owner. However, a schedule cannot be deleted if the detach would leave it with no jobs, unless the caller is the schedule owner.

Only members of the sysadmin role can delete a job schedule that is owned by another user.

Examples#

A. Deleting a schedule The following example deletes the schedule NightlyJobs. If the schedule is attached to any job, the example does not delete the schedule.

EXEC dbo.sp_delete_schedule @schedule_name = N'NightlyJobs';
  1. Deleting a schedule attached to a job

The following example deletes the schedule RunOnce, regardless of whether the schedule is attached to a job.

EXEC dbo.sp_delete_schedule
    @schedule_name = 'RunOnce',
    @force_delete = 1;