19 November 2010

Add a SQL JOB in SQL Server 2005

SQL Server Agent allows you to automate a variety of administrative tasks. In this tutorial, we walk through the process of using SQL Server Agent to create and schedule a job that automates database administration.  

Step 1 

Connect to the database engine of SQL server using SQL Server Management Studio.

 

Step 2
Open up Microsoft SQL Server Configuration Manager and locate the SQL Server Agent service. If the status of that service is "RUNNING", you do not need to do anything. Otherwise, right-click on the SQL Server Agent service and select Start from the pop-up menu. You'll see the Starting Service

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

Step 3 

Next, right-click on the Jobs folder and select New Job from the start-up menu. You'll see the New Job creation window shown bellow. Fill in the Name field with a unique name for your job (being descriptive will help you manage jobs better down the road!). Specify 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.
Use the large Description text field to provide a detailed description of the purpose of your job. Write it in such a way that someone (yourself included!) would be able to look at it several years from now and understand the purpose of the job.
Finally, ensure that the Enabled box is checked.
 

A New Job popup will appear. Specify the name of the job.

Step 4

Cilck next on the "Steps" in the left menu. A sql job can contain one or more steps. A step might be simply an sql statement or a stored procedure call. Add you step here
 
Next, you'll need to add the individual steps for your job. Click 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. 
After successfully validating the syntax, click OK to create the step. Repeat this process as many times as necessary to define your desired SQL Server Agent job.

Job step added

Step 5

Finally, you'll want to set a schedule for the job by clicking the Schedule icon in the Select a Page portion of the New Job window. You'll 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. 

A sql job can contain one or more schedules. A schedule is basically the time at which sql job will run it self. You can specify recurring schedules also.
Job schedule added
You SQL job is ready now. However there are other thing you can use if needed like Alert, Notifications etc.

No comments:

Post a Comment