Search code examples
sqlsql-serversql-agent-jobsql-agent

Query to list the job names and step associated with a particular table


Is there any way to search and find ,what job holds a particular table refresh . There are multiple sql agent jobs with multiple steps.What is the sql query to search all jobs and locate the job name and steps?

This is to identify the steps associated with a table load


Solution

  • Take a look at this:

    Querying SQL Agent Jobs

    use msdb
    
    SELECT 
        [sJOB].[job_id] AS [JobID]
        , [sJOB].[name] AS [JobName]
        ,step.step_name
        ,step.command
    FROM
        [msdb].[dbo].[sysjobs] AS [sJOB]
        LEFT JOIN [msdb].dbo.sysjobsteps step ON sJOB.job_id = step.job_id
    
    WHERE step.command LIKE '%MYTABLENAME%'
    ORDER BY [JobName]