How can I determine the status of a job?
To quickly find the status of a SQL job, run a succinct query on msdb.dbo.sysjobhistory. The outcome of the job is indicated by run_status; 0
translates to a failure and 1
indicates success. Here's how:
This command will fetch the most recent status for all tasks, sorted in descending order by instance_id.
Delving Deeper: Advanced Techniques for Job Status
Unwrapping the Activity and Session Information Package
Suspecting a currently active job? You'll need some extras! The sysjobactivity and syssession tables, when connected with the sysjobs_view, reveal more intriguing information:
This will fetch all active jobs and their running times, sorted beginning from the longest running.
Looking Back: Past-Execution Outcomes Review
For the history buffs out there, querying msdb.dbo.SysJobHistory provides an interesting peek back:
This provides historical data on job failures, complete with time stamps and charming error messages!
Taking Pulse: Real-time job activity
Pop in and see what's cooking right now! The sp_help_job
stored procedure serves up data hot off the job grill:
This delivers a snapshot of currently active jobs, just in the nick of SQL execution time.
Mind the Details: Deep Analysis and Prevention
Knowledge is Power: Understanding Job System Tables
Being familiar with MSDN documentation on job-related system tables is akin to knowing the minions who do behind-the-scenes work. These smart tables store metadata and logs about jobs, hosting deep analysis and troubleshooting:
sysjobs
: A roll call list for all jobs.sysjobactivity
: A diary of current and past job activities.sysjobhistory
: Personal notes of executed job outcomes.sysjobsteps
: An itinerary of steps associated with each job.sysjobservers
: The introverted tables giving a detail about the servers involved with each job.
False Positives: Sneak-thieves Caught!
When combining tables like sysjobactivity and syssessions, it's savvy to limit the joins to the current session. This helps you avoid putting older session data in the 'Currently in Action' cabinet:
Job Activity Peek Boxes
Use sp_help_jobactivity
stored procedure to get a running commentary of current job hustle-bustle:
Taking Stock of Time
For those running jobs, the ticking alarm is elapsed time. Here's how you could play the timekeeper using DATEDIFF:
Was this article helpful?