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

user1254579 picture user1254579 · May 31, 2018 · Viewed 10.7k times · Source

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

Answer

B3S picture B3S · May 31, 2018

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]