Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SQL Server Find What Jobs Are Running a Procedure

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

like image 204
Lloyd Banks Avatar asked Aug 06 '12 12:08

Lloyd Banks


People also ask

How do you see what SQL jobs are running?

Using SQL Server Management Studio Expand SQL Server Agent. Right-click Job Activity Monitor and click View Job Activity. In the Job Activity Monitor, you can view details about each job that is defined for this server.

What is Run_status in Sysjobhistory?

It contains the history of the SQL agent jobs that run and perform operations on the server. Each row of the table corresponds to a step in the job. There is a column in the table called run_status, that gets an integer value to indicate the outcome of the job when it completed and got written into the table.

How do I find SQL Agent employment history?

To view the job history log Expand SQL Server Agent, and then expand Jobs. Right-click a job, and then click View History. In the Log File Viewer, view the job history. To update the job history, click Refresh.


1 Answers

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.

like image 50
Aaron Bertrand Avatar answered Sep 30 '22 08:09

Aaron Bertrand