Adding Existing Jobs as Subplans to Maintenance Plan

  • I have a couple of jobs I'd like to consolidate into one maintenance plan. When I create a new maintenance plan, I am only given the option of creating new subplans instead of adding existing jobs as subplans. Does anyone know how I can add exisiting jobs as subplans?

  • Maybe with "sp_start_job" in a TSQL Script Step

    Like

    IF (SELECT DATENAME(DW,GETDATE())) <> 'Sunday'

    BEGIN

    exec sp_start_job @job_name = 'YourJob',@step_name = 'StepOne'

    END

    ELSE

    BEGIN

    exec sp_start_job @job_name = 'YourJob2',@step_name = 'StepFour'

    END

    In fact one job trigger the others jobs.

    Jeff.

  • I'm not sure I understand the question.

    1. When you are talking about a "maintenance plan," are you speaking of using the wizard to do this in SSMS?

    2. Why would you want to have a job run other jobs as a part of the step. Why not move the steps from the other jobs and make the steps into their own job? Are you trying to have these things run asynchronously? i.e. what is the objective here?

    Jared
    CE - Microsoft

  • Hi, I am referring to the "Maintenance Plans" section under "Management" ? "Maintenance Plans" in the Object Explorer panel. When you create and schedule "Maintenance Plans" using the wizard, jobs are auto-created under "SQL Server Agent". I have several existing jobs that already runs on a schedule, but that I would like to incorporate into a new maintenance plan

  • Well, personally, I would create a new maintenance plan with all that is needed and then get rid of the others. Jobs have steps so that you do not have a job running other jobs. It almost defeats the purpose to have a job run other jobs, unless there is a reason that it cannot be done any other way. Now, IMHO, maintenance plans are best for more inexperienced users/businesses where a DBA is not on site. I would always prefer to write my own scripts and place then into separate steps.

    Jared
    CE - Microsoft

  • Create a New Maintenance Plan (don't choose the Maintenance Plan Wizard). Give the Plan a name. Make sure the SSMS Toolbox is open. Drag the "Execute SQL Server Agent Job Task" option to the designer pane of the maintenance plan. Double-click the task and a list of SQL Server Agent tasks will be present.

  • Better still rewrite the whole thing as an SQL Agent job (or jobs) and get rid of those Maintenance plans!!

    ...

Viewing 7 posts - 1 through 6 (of 6 total)

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