• subscribe
May 20, 2003 12:00 AM

Generating Scripts for SQL Server Jobs

SQL Server Pro
InstantDoc ID #38790
Downloads
38790.zip

How can I generate scripts for all jobs running on my SQL Server? I want one script that includes all jobs and one script for each individual job.

You can use SQL Distributed Management Objects (SQL-DMO) to obtain a list of jobs. Use the JobServer object and iterate through the Jobs collection. To obtain each job's script, you can call the Scripts method for that job. Here's what you should do:

  1. Start Visual Basic (VB) 6.0.
  2. Start a standard EXE project.
  3. Add a command button.
  4. Double-click the new command button to get the click event code window.
  5. From the main VB menu, select Project, References. Scroll through the References list to find the Microsoft SQLDMO Object Library and add it. Try to use the .dll file that shipped with the version of SQL Server you're running the .dll against. You can find the .dll version by looking at the location the .dll comes from in the window you have open.
  6. To fetch all of your jobs, paste the code that Listing 4 shows into the click handler for the button. Review the Change if required lines, then run the program.

If you want to script jobs interactively, you can do so from Enterprise Manager by right-clicking jobs and choosing All Tasks, Generate SQL Script.



ARTICLE TOOLS

Comments
    There are no comments to display. Be the first one!
You must log on before posting a comment.

Are you a new visitor? Register Here
  • SP1?
    I know there is a SP1 for SQL 2008 R2 available....and there is a "feature pack" as well... ...
  • SQL database mirroring
    I have SQL Server 2008 R2 Enterprise 64bit on Windows 2008 R2 Enterprise 64bit.  Each SQL Server has...
  • Dell Compellent Disk Drive
    Does anybody has experience with Dell Compellent Disk Drive? Basically, this system manages all disk...
  • Sql server performance tuning
    I need to find a tool that help me to optimize sql server,queries,improve the performance and solve ...