Friday, 7 December 2012

MS-SQL - Create Job in Sql Server 2008

MS-SQL - Create Job in Sql Server 2008
In this article i will show you how to create a Job in Sql Server 2008.

Step 1
Download Northwind database from the following link.

Step 2
Attach a Northwind database into MS-SQL server.

Step 3
Expand the SQL Server Agent. You will see a Jobs folder over there. Right click on jobs and choose Add New. 

Step 4

Create a New Sql Server Agent Job.

New Job creation window shown above. Fill in the Name field with a unique name for your job. Specfy the account that you wish to be the owner of the job in the Owner text box. The job will run with the permissions of this account and may only be modified by the owner or sysadmin role members. 

Once you've specified a name and owner, choose one of the predefined job categories from the drop-down list. For example, you might choose the"Database Maintenance" category for routine maintenance jobs but for this example select only Uncategorized [local] only.

Finally, ensure that the Enabled box is checked.

Step 5

Enter the SQL Server Agent Job Steps Screen.

Next click on the ‘Steps’ pane on the left and you’ll be presented with this screen.  It’s blank because you haven’t created any steps yet.  So go ahead and click on the ‘New’ button at the bottom.

Step 6

Add SQL Server Agent Job Steps.

After Clicking  the New button to create a new job step and you will see the New Job Step window shown above.

Use the Step Name textbox to provide a descriptive name for the Step. 

Use the Database drop-down box to select the database that the job will act upon. 

Finally, use the Command textbox to provide the Transact-SQL syntax corresponding to the desired action for this job step. Once you have completed entering the command, click the Parse button to verify the syntax and then click on OK button.

In this job i am taking backup Northwind database to the disk.

       BACKUP DATABASE Northwind  
       TO DISK = 'd:\NorthwindBackUp.bak'  

Step 7

Create Schedule the SQL Server Agent Job.

To schedule your job, just click on ‘Schedules’ on the left and then choose the schedule that’s right for you then click on new button.

Step 8
Add Schedule the SQL Server Agent Job.

After Clicking  the New button to create a new job schedule and you will see the New Job Schedule window shown above.

Provide a name for the schedule in the Name text box and choose a schedule type (One-time, Recurring, Start when SQL Server Agent Starts or Start When CPUs Become Idle) from the drop-down box. Then use the frequency and duration sections of the window to specify the job's parameters. When you are finished click OK to close the Schedule window and OK to create the job.

Your job is ready now.

Step 9
For the testing purpose execute job first time. 

Right Click on the Job and click on Start job at Step and you will see the Start Jobs window will open. 

No comments:

Post a Comment