Free Web Development Online Tutorials, Learn to Code
Learn SQL Database Development, MS SQL Tutorial Online

How to create jobs in sql server

What is Job in SQL Server
A job in SQL server is basically a bunch of tasks (queries) performed sequentially by SQL Server Agent.

Create job in SQL server 2005, 2012

job in sql 2005

  • Open the SQL Server Management Studio on your local window and you should have the “SQL Server Agent” installed
  • Expand the "SQL Server Agent" in Object Explorer
  • Right click on the Jobs and select the "New Job"
  • You will see a new window, give a valid name for new job, and click "Ok" button.
  • At this point a new job has been created; you can refresh the explorer to see the new job, right click to see properties and set configuration details

How to call a SQL JOB from Stored PROCEDURE

Normally SQL Jobs are created for automation, means things can be carried out without further human interaction, but there are situation where jobs needs to be executed on demand or in some conditional situation.

Here we create a simple store procedure to execute JOB

CREATE PROC mySpToExecutejob 
AS
	EXEC dbo.sp_start_job N'Monthly Newletter' ;  
GO

Now you can call the store procedure from SQL code or execute directly

EXEC mySpToExecutejob
Comment
Name
Email
Website
Subscribe