Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to run a stored procedure in sql server every hour?

I have a table on which I want to perform some operations every hour. For this I created a Stored Procedure but don't know how to call it every hour. I know there are some kind of scheduled jobs, but how to use them.

Is there some kind of service also that keeps on running continuously, every second, where I can place my piece of code to be executed ?

like image 320
Shantanu Gupta Avatar asked Feb 27 '10 20:02

Shantanu Gupta


People also ask

Can a stored procedure run on a schedule?

Still, there are few methods to schedule the execution of a stored procedure. For example, we can use the Windows Task Scheduler to schedule the execution of a script that consists of the execution of a procedure. For more detail, you can refer to the SQL Server schedule stored procedure without an agent.

Do stored procedures run automatically?

A stored procedure that is set to automatic execution runs every time an instance of SQL Server is started. Blocks the execution of a batch, stored procedure, or transaction until a specified time or time interval is reached, or a specified statement modifies or returns at least one row.

Can we schedule stored procedure in SQL Server?

In SQL Server Management Studio, go expand the SQL Server Agent node under the DB server, right click the Jobs folder and select New Job... That will take you through a wizard to schedule a sproc to run on whatever schedule you want.


1 Answers

In SSMS navigate to SQL Server Agent-->Jobs Right click on the Job Folder and select new job

on the dialog that pops up, give the job a name click on steps, then on new, you will see a dialog like the following, pick correct DB and type your proc name

alt text

after that click on schedule, pick new and you will see something like the image below, fill all the stuff you need and click ok, click ok on the job and you should be set alt text

like image 150
SQLMenace Avatar answered Sep 25 '22 13:09

SQLMenace