Redigera

Dela via


Create a Job Category

Applies to: SQL Server Azure SQL Managed Instance

Important

On Azure SQL Managed Instance, most, but not all SQL Server Agent features are currently supported. See Azure SQL Managed Instance T-SQL differences from SQL Server for details.

This article describes how to create a job category in SQL Server by using SQL Server Management Studio, Transact-SQL or SQL Server Management Objects.

SQL Server Agent provides built-in job categories that you can assign jobs to, or you can create a job category and assign jobs to it. Job categories help you organize your jobs for easy filtering and grouping. For example, you can organize all your database backup jobs in the Database Maintenance category. You can also create your own job categories.

Before You Begin

Limitations and Restrictions

Multiserver categories exist only on a master server. There is only one default job category available on a master server: [Uncategorized (Multi-Server)]. When a multiserver job is downloaded, its category is changed to Jobs From MSX at the target server.

Security

For detailed information, see Implement SQL Server Agent Security.

Using SQL Server Management Studio

To create a job category

  1. In Object Explorer, select the plus sign to expand the server where you want to create a job category.

  2. Select the plus sign to expand SQL Server Agent.

  3. Right-click the Jobs folder and select Manage Job Categories.

  4. In the Manage Job Categoriesserver_name dialog box, select Add.

  5. In the new dialog box, in the Name box, enter a name for the new job category.

  6. Select the Show all jobs check box. Select one or more jobs for the new category by checking the boxes corresponding to the jobs.

  7. Select OK.

  8. In the Manage Job Categoriesserver_name dialog box, select Refresh to ensure that the new job category is active. If everything looks as expected, close this dialog box.

For more information on these dialog boxes, see Job Categories - Manage Job Categories and Job Categories Properties - New Job Category.

Using Transact-SQL

To create a job category

  1. In Object Explorer, connect to an instance of Database Engine.

  2. On the Standard bar, select New Query.

  3. Copy and paste the following example into the query window and select Execute.

    -- creates a local job category named AdminJobs
    USE msdb ;
    GO
    EXEC dbo.sp_add_category
        @class=N'JOB',
        @type=N'LOCAL',
        @name=N'AdminJobs' ;
    GO
    

For more information, see sp_add_category (Transact-SQL).

Using SQL Server Management Objects

To create a job category

Call the JobCategory class by using a programming language that you choose, such as Visual Basic, Visual C#, or PowerShell. For example code, see Scheduling Automatic Administrative Tasks in SQL Server Agent.