Saturday, March 19, 2011

SQL Server Job Scheduling

Job Scheduling

A. Creating and viewing the jobs from management studio:

SQL Server Agent should be up and running:

clip_image002

clip_image004

B. Creation of jobs:

clip_image006

clip_image008


C. Executing a job through an SP:

EXEC msdb.dbo.sp_start_job @job_name=N'test'

Some of the SPs that are called internally by SQL Server while creating the jobs are:

msdb.dbo.sp_add_category

msdb.dbo.sp_add_job

msdb.dbo.sp_add_jobstep

clip_image010

msdb.dbo.sp_update_job

msdb.dbo.sp_add_jobschedule

msdb.dbo.sp_add_jobserver

Deleting the job through T-SQL:

IF EXISTS (SELECT job_id FROM msdb.dbo.sysjobs_view WHERE name = N'test1')

EXEC msdb.dbo.sp_delete_job @job_name=N'test1', @delete_unused_schedule=1

All the jobs are stored in msdb database.


D. Executing an SQL server job through SSIS:

clip_image012

The connection should be pointed to the server where the job is placed and the particular job to be executed is selected:

clip_image014

E. History of jobs:

Check the history of jobs to check why the job failed or whether it succeeded:

clip_image016

clip_image018

F. Creation of a job to execute an SSIS package:

Select type as “SQL Server Integration Services Package”

If the package is stored in the file system, then select file system as the package source and browse through to the dtsx package. Else if the package is stored in the SQL server, then select SQL Server as the package source:

clip_image020

No comments: