Tuesday, 23 September 2014

Scheduling a Job in SQL Server

Explained step by step in this blog
 
 
 
Scheduling Data Imports in SQL Server
Part three of a three-part series of blogs
If you frequently import data into a SQL Server database from the same source you'll probably be sick of going through the import wizard again and again. So why not learn how to schedule an automatic import of your data using SSIS packages and the SQL Server Agent? This blog explains how to do exactly that!
  1. Scheduling Data Imports in SQL Server
  2. Using the Import Wizard in SQL Server
  3. Scheduling a Job in SQL Server (this blog)

Scheduling a Job in SQL Server

The final stage of this blog series is to create a scheduled job to execute the SSIS package on a regular basis.

The SQL Server Agent

You can schedule jobs using the SQL Server Agent.  You should find this at the bottom of the list of objects in any database server that you've connected to in SQL Server Management Studio:
SQL Server AgentThe SQL Server Agent appears at the bottom of the list of objects in a database server.
 

Creating a Job

To create a new job using SQL Server Agent:
Creating a new jobRight-click the Jobs folder and choose New Job...
 
You can then use the dialog box to set up the job you want to create.  The steps we need to follow in order to schedule our SSIS package execution are described below.

Step 1 - Enter a Name for the Job

The first step is to give the new job a sensible name, as shown below:
Naming a jobIn the General category, enter a descriptive name for the job.

Step 2 - Create the Job Steps

Next, you can create the steps that will make up the job.  Our job should have only one step and here's how to create it:
  1. Select the Steps page of the dialog box.
Create job stepsBuild a list of steps for the job using this page of the dialog box.
  1. Click the New... button to add a new step to the job.
Specify the job stepUse this dialog box to specify the settings for this job step.
  1. Enter a sensible name for this step of the job.
  2. Choose the type of action to perform.  Here we want to execute an SSIS package.
  3. Choose where the SSIS package is stored.  Here we've selected the package that we saved earlier on our SQL Server.
  4. Click the ellipsis (...) to choose the package you want to execute.
  5. Click OK to return to the New Job dialog box.
The job should now consist of a single step:
Step in jobOur entire job consists of a single step, but we could always add more to this by clicking the New... button at the bottom of the dialog box.

Step 3 - Creating the Job Schedule

To ensure that the job runs at a specific time you need to specify the schedule for the job.  To do this:
  1. Select the Schedules page of the dialog box.
Scheduling a jobUse this page to set up the job schedule.
  1. Click New... to create a new schedule.
  2. Complete the dialog box as shown below:
Schedule setupThe options in this page of the dialog box are self-explanatory. The options we have selected here ensures the job will be carried out each week at 9am on a Monday morning.
  1. Click OK to return to the New Job dialog box.

Step 5 - Creating the Job

When you have finished applying all of the settings listed above, you can create the job by simply clicking OK on the New Job dialog box.
Job createdYour new job will appear in the Jobs folder within SQL Server Agent.
 
And that's it!  As long as your database server is running and SQL Server Agent has been started your data import will occur on a scheduled basis from now on.


Reference

http://www.wiseowl.co.uk/blog/s231/schedule_data_import_in_sql_server_pt3.htm


No comments:

Post a Comment