Reputation: 3303
I have two sql server agent jobs: Job1 and Job2. Since Job2 is very similar to Job1, I right-clicked on Job1 > Script Job As > Create To
and used that script to create the Job2.
Now I'm seeing that any change I make in the schedule of Job2 is also affecting Job1, and I'm assuming that it's happening because both have the same @schedule_uid
.
So, two questions:
Is it correct to generate a job by using the sql script of another job? If it's correct, how can I fix this error where changes made in one job affect the other job?
Thanks.
Upvotes: 0
Views: 1292
Reputation: 1789
If you look in your script you will see that the @schedule_uid
is the same. If you would fetch the new @schedule_uid
(and all other hardcoded id's) from the tables in the MSDB
database you will get a correct running job
Upvotes: 1
Reputation: 12243
Schedules are distinct objects within SQL Server and as you have found are independent to the Job, referenced by an ID.
If you are creating jobs via script you just need to either not assign a schedule, create a new schedule as well for every job, or define a set of possible schedules that fit around your requirements/maintenance windows and specify the correct ID in your script.
Obviously any two jobs that share a schedule will be affected if you change the schedule so, if you foresee a lot of individual job management/tweaking going on, it may be best that your script creates a schedule and then reference that new schedule in the job creation.
Upvotes: 1