Sunday 30 December 2018

Adding new (custom) SQL server job category

We can add new or custom job category in the SQL Server agent. We can add a category by two way.
o   Using system SP msdb.dbo.sp_add_category
o   Using GUI
 These values are stored on the system table syscategories
select * from msdb.dbo.syscategories
     

Let’s See  
To add the new category we will use Sp_add_category SP. Before adding we need to this object in the table if object is exist then in this case we need to update this category otherwise we will add. 
IF (SELECT COUNT(*) FROM msdb.dbo.syscategories 
   WHERE category_class = 1 AND category_type = 1  
       AND [name] = 'My New Category') < 1
EXECUTE msdb.dbo.sp_add_category @class = 'JOB',
@type = 'LOCAL', @name = 'My New Category'

Executing this code
  
 
Here I am using class =job and type = local.


New custom job is created. See it in the table.
  
We can see this on the new job window.
  

Another way to add new category is to use the GUI.
Right click on the job and select manage job categories.
   

After clicking on the Manage job categories we will get the new window.
  

Here we will get the number of jobs against each category.
If we want to add new category we need to click on the Add button.
     

Click ok.
A new category added.
   

We can delete the category. Click on the delete button.
  

Select the category and click on the delete button we will get the warning message. Now click on yes button. Category is deleted.
 


Hope this will be helpful to create and manage SQL server job agent category.

1 comment:

If you have any doubt, please let me know.

Popular Posts