Microsoft Learn

MSDN Documentation > SQL Server > SQL Server Agent

SQL Server Agent

SQL Server Agent is a Microsoft SQL Server service that executes scheduled tasks, known as jobs. Jobs can run Transact-SQL scripts, Command Shell scripts, PowerShell scripts, and other types of steps.

Overview

SQL Server Agent provides a robust platform for automating database maintenance, administration, and management tasks. It allows you to schedule jobs to run at specific times, in response to specific events, or on a recurring basis. This ensures that routine operations are performed consistently and reliably, freeing up database administrators to focus on more critical tasks.

SQL Server Agent Architecture Diagram

Key Features

Getting Started

To begin using SQL Server Agent, ensure the SQL Server Agent service is running. You can manage SQL Server Agent through SQL Server Management Studio (SSMS).

Creating a Simple Job

  1. Open SQL Server Management Studio and connect to your SQL Server instance.
  2. In Object Explorer, expand the folder for your SQL Server instance.
  3. Expand SQL Server Agent.
  4. Right-click on Jobs and select New Job....
  5. In the New Job dialog, enter a Name for your job (e.g., "Daily Database Backup").
  6. Navigate to the Steps page and click New... to add a job step.
  7. For a T-SQL step, select "Transact-SQL script (T-SQL)" as the Type.
  8. Enter the T-SQL command to execute, such as a backup command:
    BACKUP DATABASE [YourDatabaseName] TO DISK = 'C:\Backups\YourDatabaseName_Full.bak' WITH COMPRESSION, STATS = 10;
  9. Click OK to save the step.
  10. Navigate to the Schedules page and click New... to create a schedule.
  11. Configure the schedule details (e.g., frequency, time of day).
  12. Click OK to save the schedule and the job.

Common Tasks

Related Technologies