Generate job script from existing jobs

  • We have around 40+ jobs in the server box which hosts 5 DB instances

    , of which i need to script some of the jobs to be run on a different server for testing.

    I need all the jobs which use a particuler DB only .

    Is there any Way i can filter and genrate scripts from SQLAgent,

    If i give a 'wordsearch' like the DB name ,

    Please advice....

  • any suggestions??

  • You could query the MSDB to search for jobs with the DatabaseName you're interested in. At least that would give you the list of jobs you then would need to script manually through SSMS.

    select distinct j.name from sysjobs j join sysjobsteps s on j.job_id = s.job_id

    where s.command like '%DatabaseName%'

  • there are dozens of scripts here on SSC for scripting out jobs:

    http://www.sqlservercentral.com/search/?q=script+jobs&t=s

    so from there you could then add a WHERE filter to any of those to limit to a specific database.

    some jobs never explicitly mention a database name even thought hey fiddle with them...they might be querying sys.databases, or using dynamic sql to get database names, and run a loop / cursor thru the contents...so you need to take that into consideration as well.

    Lowell


    --help us help you! If you post a question, make sure you include a CREATE TABLE... statement and INSERT INTO... statement into that table to give the volunteers here representative data. with your description of the problem, we can provide a tested, verifiable solution to your question! asking the question the right way gets you a tested answer the fastest way possible!

Viewing 4 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic. Login to reply