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

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.


If you script a job, it will script a schedule, including a GUID that should be created just fine if it doesn't yet exist on the new server. E.g.:

EXEC @ReturnCode = msdb.dbo.sp_add_jobschedule
        @job_id=@jobId, @name=N'syspolicy_purge_history_schedule', 
        @enabled=1, 
        @freq_type=4, 
        @freq_interval=1, 
        @freq_subday_type=1, 
        @freq_subday_interval=0, 
        @freq_relative_interval=0, 
        @freq_recurrence_factor=0, 
        @active_start_date=20080101, 
        @active_end_date=99991231, 
        @active_start_time=20000, 
        @active_end_time=235959, 
        @schedule_uid=N'3706c58c-cad3-481f-a565-2e1aed81ee8e'
   ---------------------^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

It's ok to use this number on the new server, as long as you haven't already migrated another job that used the same schedule.

If you have, and you get errors, the whole thing will be rolled back. In this case you really should comment out this section and just manually assign the same schedule to this job. If you're really lazy, though, you could just change a couple of characters in the GUID.