Compartilhar via


sp_delete_schedule (Transact-SQL)

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.

    Note

    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.

Return Code Values

0 (success) or 1 (failure)

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. Other users must be granted one of the following SQL Server Agent fixed database roles in the msdb database:

  • SQLAgentUserRole
  • SQLAgentReaderRole
  • SQLAgentOperatorRole

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.

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.

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

See Also

Reference

sp_add_schedule (Transact-SQL)

Other Resources

Implementing Jobs

Help and Information

Getting SQL Server 2005 Assistance