sp_attach_schedule (Transact-SQL)
SQL Server 2008
Sets a schedule for a job.
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.
SQL Server checks if the user owns both the job and the schedule.
The following example creates a schedule named NightlyJobs. Jobs that use this schedule execute every day when the time on the server is 01:00. The example attaches the schedule to the job BackupDatabase and the job RunReports.
Note |
|---|
This example assumes that the job BackupDatabase and the job RunReports already exist. |
USE msdb ;
GO
EXEC sp_add_schedule
@schedule_name = N'NightlyJobs' ,
@freq_type = 4,
@freq_interval = 1,
@active_start_time = 010000 ;
GO
EXEC sp_attach_schedule
@job_name = N'BackupDatabase',
@schedule_name = N'NightlyJobs' ;
GO
EXEC sp_attach_schedule
@job_name = N'RunReports',
@schedule_name = N'NightlyJobs' ;
GO
