SQL Server Find What Jobs Are Running a Procedure

Lloyd Banks picture Lloyd Banks · Aug 6, 2012 · Viewed 60.9k times · Source

Is there a way to find out what jobs are using a certain stored procedure?

Answer

Aaron Bertrand picture Aaron Bertrand · Aug 6, 2012

This will capture instances where the procedure is explicitly referenced in the job step:

SELECT j.name 
  FROM msdb.dbo.sysjobs AS j
  WHERE EXISTS 
  (
    SELECT 1 FROM msdb.dbo.sysjobsteps AS s
      WHERE s.job_id = j.job_id
      AND s.command LIKE '%procedurename%'
  );

If it is called by something else that is called from the job, or the command is constructed with dynamic SQL, this might be a little more difficult to track down. Note also that if your procedure name can also appear naturally in other code, comments, etc. that it may produce false positives.