SQL Server Agent Jobs
SQL Server Agent is a built-in SQL service used to automate and schedule tasks such as :
- Run SQL scripts at scheduled times in SQL Server Job
- Back up databases
- Rebuild or reorganize indexes
- Update statistics
- Execute SSIS (SQL Server Integration Services) packages
- Run PowerShell scripts or Command Prompt commands
- Send alerts or email notifications
- Monitor SQL Server events and performance
For example, suppose you need to run SQL scripts to process records in a specific database on a daily basis at midnight and you do not want to depend on an external process or application to do this job . You can create a SQL job containing these scripts and schedule it to run once at midnight, or at any specific interval (seconds, minutes, or hours). Once configured, this job will automatically execute on schedule without my intervention.
We will focus in this article on how to create SQL Server Job
It is important to note that the SQL Server Agent service is available in all SQL Server editions except the Express edition.
Before proceeding, please make sure the service is running by checking the SQL Server Agent status in the Windows Services console
How to create a SQL job
If you want to start automating SQL script or Backup Database or perform some tasks on scheduled time , you can start from SQL Server Agent , there will be object called Jobs underneath it , right click on Jobs and choose New Job
There are several pages in the job configuration window below. The first page is General, which contains the following settings:
- Name: You can choose a name that clearly represents the task or tasks you intend to execute.
- Owner: By default, this is set to the user currently logged into the SQL engine. The owner is the account that has full control over the job.
- Category: This is used to group jobs using organizational tags. Your selection here is strictly for organization and has no effect on the actual execution process.
- Enabled: This checkbox is used to enable or disable the job.
Next is the Steps page, where you can define one or more SQL scripts (e.g., INSERT, DELETE, UPDATE, EXEC SP) or scripts related to rebuild indexes , update statistics , DBCC commands . Depending on the task you are automating, your job may consist of one or multiple steps.
Get Abdellateef Ibrahim’s stories in your inbox
Join Medium for free to get updates from this writer.
For example, you might create a first step that inserts records into Table X and updates them based on a specific condition, followed by a second step that deletes records from Table Y based on a different condition.
To configure this on the Steps page, begin by clicking New:
A new window for the step settings will open. Here, you can provide a meaningful name for the step, such as “Insert Step,” and make sure the correct database context is selected. Finally, in the Command field, place the SQL script that you want to execute:
After click on Ok, the step will be saved, you can repeat the step for table y as a second step:
Next is the Schedules page, which is where you define when the SQL job will run. The schedule depends on the nature of your task. Some tasks need to be executed periodically, such as database backups or index rebuilds. Other tasks may only need to run once a day or week, while some depend on a specific day and time (for example, every Friday at 5:00 AM).
Here is a detailed explanation of the options available under Schedule type:
- Start automatically when SQL Server Agent starts: When you select this option, the other scheduling fields (such as the specific date, time, or frequency) will be disabled. The job will simply run whenever the SQL Server Agent service is started.
- Start whenever the CPUs become idle: This allows the job to execute once CPU usage falls below a specific threshold. You can define this threshold by right-clicking SQL Server Agent, selecting Properties, navigating to the Advanced page, and setting the Idle CPU condition. Note that you must enable this condition in the Agent properties before you can use this schedule type.
- Recurring: The job will run repeatedly based on a regular frequency. The configuration options for recurring schedules are explained in detail below.
- One time: The job will run exactly once. You will need to specify the exact date and time for its execution.
Once you select Recurring, you will have a wide range of options to configure depending on the nature of your task. You can set the overall frequency to run daily, weekly, or monthly, and choose the specific days it should execute. Additionally, you can configure the daily frequency to run just once a day, or repeatedly every specified number of hours, minutes, or seconds.
Finally, you can set a duration for the schedule. For example, if you only want the job to run for the next month, you can specify an exact End date for the schedule to stop.
After set the schedule you want, you can click on Ok and it will be listed below:
As a result, you can now say the job was created and you can monitor its history by right click on the job itself and choose view history:
There will be other articles on SQL Server Agent and how to monitor the jobs status if completed , succeeded or failed . Also , articles related to triggering SQL Server Alerts from SQL Agent.











