Need to find all scheduled jobs and SQL they execute for particular 3 tables

  • I want to run a query, against MSDB I assume, that will show me all scheduled jobs and sql statements that they execute at each step for particular three tables. Say, Table1, Table1, and Table3. I don't want to see any other info but only on Agent Jobs that use names of one of these three tables in one of the SQL Statements that jobs steps execute.

    Is this possible to achieve? Does anyone know about an existing script that does it?

    Likes to play Chess

  • Query sysjobsteps to get the SQL statements.  Join to sysjobs to get the name of the jobs.

    John

  • Ok. Thanks.

    I got it this way:

    SELECT

    job.job_id,

    notify_level_email,

    name,

    enabled,

    description,

    step_name,

    command,

    server,

    database_name

    FROM

    msdb.dbo.sysjobs job

    INNER JOIN

    msdb.dbo.sysjobsteps steps

    ON

    job.job_id = steps.job_id

    WHERE

    sysjobsteps.Command like '%table1%'

    OR

    sysjobsteps.Command like '%table2%'

    Likes to play Chess

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

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