by Andrei Hetel
17. March 2010 10:56
Recently I had to do some tasks on a SQL Server database with performance problems. Actually, huge performance problems caused by about 40 server jobs averaging 5-6 job steps. Why so many jobs? Because developers were programmers, not DBAs - and a programmer usually think at a row-by-row level. Most of jobs can be replaced with triggers, but this is another story.
In a scenario like this, a big problem could be to see if a certain stored procedure is used or not. Rather than iterating through all job steps, you can write a query something like:
SELECT
j.Name AS jobName,
js.Step_id,
js.STEP_NAME AS StepName,
js.Last_Run_Date,
js.Last_Run_Time,
js.Database_Name,
js.command,
j.enabled AS JobEnabled
FROM
msdb..SYSJOBS j, msdb..SYSJOBSTEPS js
WHERE
j.JOB_ID=js.JOB_ID
-- AND js.command like '%My stored procedure%'
Above query will show all the job. Modify the last line to find the stored procedure you're looking for. Please note that jobs are saved in msdb system database.