Applies To: SQL Server 2014, SQL Server 2016 Preview
Targets the specified job at the specified server.
Applies to: SQL Server (SQL Server 2008 through current version).
- [ @job_id = ] job_id
The identification number of the job. job_id is uniqueidentifier, with a default of NULL.
- [ @job_name = ] 'job_name'
The name of the job. job_name is sysname, with a default of NULL.
Either job_id or job_name must be specified, but both cannot be specified.
- [ @server_name = ] 'server'
The name of the server at which to target the job. server is nvarchar(30), with a default of N'(LOCAL)'. server can be either (LOCAL) for a local server, or the name of an existing target server.
0 (success) or 1 (failure)
@automatic_post exists in sp_add_jobserver, but is not listed under Arguments. @automatic_post is reserved for internal use.
SQL Server Management Studio provides an easy, graphical way to manage jobs, and is the recommended way to create and manage the job infrastructure.
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:
For details about the permissions of these roles, see SQL Server Agent Fixed Database Roles.
Only members of the sysadmin fixed server role can execute sp_add_jobserver for jobs that involve multiple servers.
The following example assigns the job NightlyBackups to run on the local server.
This example assumes that the NightlyBackups job already exists.
USE msdb ; GO EXEC dbo.sp_add_jobserver @job_name = N'NightlyBackups' ; GO
The following example assigns the multiserver job Weekly Sales Backups to the server SEATTLE2.
This example assumes that the Weekly Sales Backups job already exists and that SEATTLE2 is registered as a target server for the current instance.
USE msdb ; GO EXEC dbo.sp_add_jobserver @job_name = N'Weekly Sales Backups', @server_name = N'SEATTLE2' ; GO