1

In SQL Management Studio, you can right click on an Agent Job and choose 'Script Job as' -> 'Create to/Drop to', which will reveal the backend code for the agent job.

Is there a script I can execute which would generate this code as well?

I've been searching for details on this, but all I can find so far is references for viewing the script via SQL Management Studio (Example 1, Example 2, Example 3).

If anyone could point me in the proper direction containing ANY details on how to query for a creation script, that would be awesome.

Kyle
  • 17,317
  • 32
  • 140
  • 246
  • Check this SO question, it points out the VS command line util that will generate the code. http://stackoverflow.com/questions/483568/how-can-i-automate-the-generate-scripts-task-in-sql-server-management-studio-2 – Vinnie Oct 20 '15 at 13:44

1 Answers1

1

Running a Profiler Trace while running the 'Script Job as' -> 'Create to' reveals a set of SQL statements that you could mimic:

enter image description here

Dave.Gugg
  • 6,561
  • 3
  • 24
  • 43
  • 1
    Thanks, I hadn't though to use a Profiler trace. For some reason I was thinking that because it was via an SQL Agent, the trace may not see it. I'll give that a go though. – Kyle Oct 20 '15 at 14:33