How To Create a SQL Server Job

 

You can create jobs on SQL Server to do certain operations at certain intervals. For example, if you want to run a script every half an hour or you may need to get backups every night. We can duplicate samples. In this article I will describe how to create a job.

Right-click Jobs under SQL Server Agent on SSMS and click New Job as follows.

 

We give a name to job in the Name section of the screen. In the owner part, we determine the owner of the job. I usually set it as sa.

 

In the Steps tab, we will create a step for the job. We come to the Steps section and click on New and we will see a screen like below.

In the Step name section, we give a name to step.

In the Type section, because we have selected Transact-SQL script (T-SQL), you should write the script you want to run in the Command section instead of “Select 1”.

 

You can do the different operations you want to do with the job by selecting the following options from the Type section.

For example running a power shell command, operating system command, or executing an executable program.

 

After creating Step, we click New from the Schedule section to determine the interval at which the job will run.

In the Name section, we give a name to Schedule. We usually choose Recurring in the Schedule type section. By making this selection, we ensure that this job works periodically.

If you select “Start automatically when SQL Server Agent starts”, the job starts when the SQL Server Agent starts.

If you select “Start whenever the CPUs become idle”, the job starts as soon as the CPU reaches the idle position.

If you select “One time”, the job only works once.

We choose Recurring and choose Daily from Occurs as follows.

You can select Daily to run Job every day, Weekly to run it on specific days and times of the week, or Monthly to run it on specific days and times of the month.

We choose 1 Days in the Recurs every section. So the job will work every day.

If we choose an hour from the Occurs once at section, it works every day at the time we choose.

We choose 2 hours from the Occurs every part. So the job will run every 2 hours every day. Click on ok to create our job.

dbtut
Author: dbtut

We are a team with over 10 years of database management and BI experience. Our Expertises: Oracle, SQL Server, PostgreSQL, MySQL, MongoDB, Elasticsearch, Kibana, Grafana.

Leave a Reply

Your email address will not be published. Required fields are marked *