sp_delete_schedule (Transact-SQL)
Deletes a schedule.
By default, members of the sysadmin fixed server role can execute this stored procedure. Other users must be granted one of the following SQL Server Agent fixed database roles in the msdb database:
-
SQLAgentUserRole
-
SQLAgentReaderRole
-
SQLAgentOperatorRole
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.
For details about the permissions of these roles, see SQL Server Agent Fixed Database Roles.
Only members of the sysadmin role can delete a job schedule that is owned by another user.
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.
USE msdb ;
GO
EXEC dbo.sp_delete_schedule
@schedule_name = N'NightlyJobs' ;
GO
B. Deleting a schedule attached to a job
The following example deletes the schedule RunOnce, regardless of whether the schedule is attached to a job.
USE msdb ;
GO
EXEC dbo.sp_delete_schedule
@schedule_name = 'RunOnce',
@force_delete = 1;
GO