3

I have a SQL Server Agent job comprised of 10 steps and each step has many parameters defined. Now I need another job almost exactly the same, but with a few differences. Since "copy / paste" isn't an option for jobs, I'm looking for suggestions on what would be the best way to create a new job based on the first.

Edit: I just noticed that I can right-click and "Script Job As". I suppose one option would be to do just that and edit the script for my changes. I'm still curious as to if there are any other (better?) options as well.

Chris_K
  • 3,434
  • 6
  • 41
  • 45

3 Answers3

8

I don't think there is a better option than scripting your job. You can modify the script as required and reapply it to any number of SQL instances (always backup your system databases before apply scripts).

SuperCoolMoss
  • 1,252
  • 11
  • 20
  • This seems to be the best way to go when copying jobs in the same instance. – Chris_K May 21 '09 at 23:59
  • 1
    Be aware that unless you remove the @schedule_uid then the new job will be created using the same schedule as the original, i.e. changes to the schedule in the copied job will also change the schedule in the original job. See this question on Database Administrators: http://dba.stackexchange.com/questions/55327/how-can-i-change-the-number-of-schedule-uid-n-to-re-create-a-sql-server-a – flash Sep 16 '14 at 13:51
2

You may find the SQL Server Integration Services Task, Copy Job to be of use.

http://msdn.microsoft.com/en-us/library/ms137568(SQL.90).aspx

John Sansom
  • 643
  • 3
  • 7
  • I had looked at that, but it doesn't seem to help me copy a task on the same instance. I guess I could copy from instance a to instance b, rename and modify and then copy back but with my ADD issues I'm sure to lose track of what I'm doing halfway through! :-) – Chris_K May 21 '09 at 14:49
2

I used the "Script Job as" and selected "Create To" and "New Query Editor Window". Once it was in the query editor window, I changed the name of the job and ran the code. It created an exact copy of the initial job on the same server. Success!

user152683
  • 21
  • 1
  • I copied a job and it didn't do exactly what I wanted. We use schedules, DTS packages, and many other elements. While this may work in theory, care should be used if the job is complicated as you may get unexpected results; in my case, the schedule for the original & copied job was co-mingled, which was not my intent. – JosephDoggie Feb 16 '16 at 20:17