Events
Mar 31, 11 PM - Apr 2, 11 PM
The biggest SQL, Fabric and Power BI learning event. March 31 – April 2. Use code FABINSIDER to save $400.
Register todayThis browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
Applies to:
SQL Server
Deletes a schedule.
Transact-SQL syntax conventions
sp_delete_schedule
[ [ @schedule_id = ] schedule_id ]
[ , [ @schedule_name = ] N'schedule_name' ]
[ , [ @force_delete = ] force_delete ]
[ , [ @automatic_post = ] automatic_post ]
[ ; ]
The schedule identification number of the schedule to delete. @schedule_id is int, with a default of NULL
.
Either @schedule_id or @schedule_name must be specified, but both can't be specified.
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 can't be specified.
Specifies whether the procedure should fail if the schedule is attached to a job. @force_delete is bit, with a default of 0
.
0
, the stored procedure fails if the schedule is attached to a job.1
, the schedule is deleted regardless of whether the schedule is attached to a job.Identified for informational purposes only. Not supported. Future compatibility is not guaranteed.
0
(success) or 1
(failure).
None.
By default, a schedule can't 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 doesn't stop jobs that are currently running.
You can grant EXECUTE
permissions on this procedure, but these permissions might be overridden during a SQL Server upgrade.
Other users must be granted one of the following SQL Server Agent fixed database roles in the msdb
database:
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 can't 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.
The following example deletes the schedule NightlyJobs
. If the schedule is attached to any job, the example doesn't delete the schedule.
USE msdb;
GO
EXEC dbo.sp_delete_schedule
@schedule_name = N'NightlyJobs';
GO
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
Events
Mar 31, 11 PM - Apr 2, 11 PM
The biggest SQL, Fabric and Power BI learning event. March 31 – April 2. Use code FABINSIDER to save $400.
Register today