Note to myself: How to easily count the number of Jobs in SQL Server Agent Jobs?

  • Sandro Pereira
  • Oct 17, 2023
  • 2 min read

This is another post for the sake of my mental sanity. I keep looking up this information again and again. Therefore, I decided to write it down once and for all.

While working on BizTalk Server projects, I often need to count SQL Server Agent jobs. The same applies when optimizing a BizTalk Server environment. In these scenarios, knowing the exact number of jobs really matters.

First, I need this number to properly configure the maximum job history log. This way, I make sure no job loses its execution history. As a result, monitoring and troubleshooting become much easier.

Usually, I only have a few SQL Server jobs. In that case, counting them manually is easy. However, it is still annoying.

Sometimes, things get more complicated. For example, I deal with SQL Server instances hosting BizTalk application databases. These environments can easily have more than 60 jobs.

At that point, manual counting is no longer just annoying. Instead, it becomes an insane and error‑prone task.

So the million-dollar question is, how to easily count the number of Jobs in SQL Server Agent Jobs?

📝 One-Minute Brief

Counting SQL Server Agent jobs can quickly become tedious in complex environments. This short note shows how to retrieve the total number of jobs in a SQL Server instance using a simple query against the msdb database, helping you manage job history, monitoring, and troubleshooting more efficiently.

To easily count the number of SQL Server Agent Jobs in your SQL Server instance, you can use a simple SQL query. Here’s how you can do it:

SELECT COUNT(*) AS NumberOfJobs
FROM msdb.dbo.sysjobs;

This query counts the number of rows in the msdb.dbo.sysjobs table, which contains information about SQL Server Agent Jobs. The result will be the total number of jobs.

Keep in mind that you need the necessary permissions to query the msdb database, which is where SQL Server Agent Jobs are stored. Typically, users with administrative roles or appropriate permissions can access this information.

Download

You can download this SQL script from GitHub:

Hope you find this helpful! If you liked the content or found it useful and would like to support me in writing more, consider buying (or helping to buy) a Star Wars Lego set for my son. 

Thanks for Buying me a coffe
Author: Sandro Pereira

Sandro Pereira lives in Portugal and works as a consultant at DevScope. In the past years, he has been working on implementing Integration scenarios both on-premises and cloud for various clients, each with different scenarios from a technical point of view, size, and criticality, using Microsoft Azure, Microsoft BizTalk Server and different technologies like AS2, EDI, RosettaNet, SAP, TIBCO etc. He is a regular blogger, international speaker, and technical reviewer of several BizTalk books all focused on Integration. He is also the author of the book “BizTalk Mapping Patterns & Best Practices”. He has been awarded MVP since 2011 for his contributions to the integration community.

Leave a Reply

Your email address will not be published. Required fields are marked *

The Ultimate Cloud
Management Platform for Azure

Supercharge your Azure Cost Saving

Learn More
Turbo360 Widget

Back to Top