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.