HiveBrain v1.2.0
Get Started
← Back to all entries
snippetsqlModerate

How can I change the number of @schedule_uid=N'????' to re-create a SQL Server Agent Job?

Submitted by: @import:stackexchange-dba··
0
Viewed 0 times
cannumberthecreatesqlagentjobschedule_uidhowserver

Problem

I have a SQL Server 2005 job in the SQL-Server Agent Jobs that I need to move/transfer to another updated SQL Server 2008 R2 instance. I was able to script it out and then use it as a new query window in the upgraded dev. server, It seems(as far as I know) that the only changes that I have to make to this script is to point it to the correct server, file path and get it a new @schedule_uid number but not sure how to assign that number.

  • This job was built for an SSIS package (as its pointing to in the file path)



Thanks for any advice

Script code is:

```
USE [msdb]
GO

/ Object: Job [eLFCopy] Script Date: 12/19/2013 11:30:57 /
BEGIN TRANSACTION
DECLARE @ReturnCode INT
SELECT @ReturnCode = 0
/ Object: JobCategory [[Uncategorized (Local)]]] Script Date: 12/19/2013 11:30:57 /
IF NOT EXISTS (SELECT name FROM msdb.dbo.syscategories WHERE name=N'[Uncategorized (Local)]' AND category_class=1)
BEGIN
EXEC @ReturnCode = msdb.dbo.sp_add_category @class=N'JOB', @type=N'LOCAL', @name=N'[Uncategorized (Local)]'
IF (@@ERROR <> 0 OR @ReturnCode <> 0) GOTO QuitWithRollback

END

DECLARE @jobId BINARY(16)
EXEC @ReturnCode = msdb.dbo.sp_add_job @job_name=N'eLFCopy',
@enabled=1,
@notify_level_eventlog=0,
@notify_level_email=0,
@notify_level_netsend=0,
@notify_level_page=0,
@delete_level=0,
@description=N'This job copies eLF files & folders from stage locations to active directories.',
@category_name=N'[Uncategorized (Local)]',
@owner_login_name=N'BIO\WDDocManagement', @job_id = @jobId OUTPUT
IF (@@ERROR <> 0 OR @ReturnCode <> 0) GOTO QuitWithRollback
/ Object: Step [RunPackage] Script Date: 12/19/2013 11:30:57 /
EXEC @ReturnCode = msdb.dbo.sp_add_jobstep @job_id=@jobId, @step_name=N'RunPackage',
@step_id=1,
@cmdexec_success_code=0,
@on_success_action=1,
@on_success_step_id=0,
@on_fail_action=2,
@on_fa

Solution

The other option to Aaron's excellent advice is to just remove @schedule_uid, the procedure will create a new UID for the schedule. That is how I moved all the jobs from our old server to our new one with out issue.

Context

StackExchange Database Administrators Q#55327, answer score: 14

Revisions (0)

No revisions yet.