Wednesday, February 28, 2018

List of all failed SQL Agent Jobs

Some SQL Agent Jobs run multiple time a day (I have see a job running every 10 seconds in Production).  SQL Agent only gives the the current state of all the jobs.  Here is how you can find all failures with their date and time.  From here, tracking down the root cause should just be a bit of investigative work.
SELECT  sysjobs.name
,sysjobhistory.run_date
,sysjobhistory.run_time
FROM msdb.dbo.sysjobs
INNER JOIN msdb.dbo.sysjobhistory
ON sysjobhistory.job_id = sysjobs.job_id
WHERE sysjobhistory.run_status = 0
AND sysjobhistory.step_id <> 0
ORDER BY sysjobhistory.run_date DESC, sysjobhistory.run_time  DESC

Wednesday, February 14, 2018

Where to find Deadlocks

All deadlock information is logged under the system_health extended event by default.  simply open system_health, right click package0.event_file > View Target Data...  At this point we can right click the grid, and select filter by this value.