Click here to Skip to main content
15,885,985 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Dear Friends,

I have created a Stored Procedure, I want it to execute for every half an hour.
Kindly any one suggest what can I do.

I use like this. Is this good practice.
while (1=1)
begin

begin try

Exec SP

waitfor delay '00:30:00'

end try
begin catch

end catch

Regards,
AP
Posted
Updated 5-Jun-12 17:56pm
v2

You need to create a SQL server job which will execute periodically

http://msdn.microsoft.com/en-us/library/ms187910.aspx[^]
 
Share this answer
 
Comments
Maciej Los 5-Jun-12 15:11pm    
Interesting answer, my 5!
Oshtri Deka 5-Jun-12 16:22pm    
I recommend this approach.
Arunprasath Natarajan 5-Jun-12 23:49pm    
I use like this. Is this good practice.
while (1=1)
begin

begin try

Exec SP

waitfor delay '00:30:00'

end try
begin catch

end catch
krumia 6-Jun-12 7:30am    
I'm not really familiar with SQL server, but I can think of few reasons why this is bad.
1. If there is a maximum execution time limit, this script is going to fail after that time limit.
2. You will have a separate permanent process/thread to execute this script, whereas a batch job will create a process every thirty minutes which will die after your procedure is finished. So doing a batch job is good for performance.
You can use the SQL Agent to set up a new job that will fire at a given interval (in your case, every half hour). Here is more information on SQL Automation:

http://msdn.microsoft.com/en-us/library/ms189880(SQL.105).aspx[^]
 
Share this answer
 
Comments
Maciej Los 5-Jun-12 15:11pm    
Interesting answer, my 5!
Arunprasath Natarajan 5-Jun-12 23:50pm    
I use like this. Is this good practice.
while (1=1)
begin
begin try
Exec SP
waitfor delay '00:30:00'

end try
begin catch

end catch
Schedule it on SQL Server Agent
SQL Jobs[^]
Also you can use SQL CMD Utility[^] with Task Scheduler[^]

Similar discussion:
How to run a stored procedure every day[^]
 
Share this answer
 
Hi,

First u see what edition u are using for sql server.

Connect to the server

SQL Server Agent - create a new job

In the General Tab fill the database name, owner, category -Database Management

Schedules - Give the name for schedule

Schedule type - Recurring and fill other details as ur need

SQL server Agent should be present in ur sql, it does not support in sql express edition
 
Share this answer
 
Comments
AmitGajjar 6-Jun-12 5:30am    
5+ good. but need formatting in your answer.
Hi,

Create a sql sever job using sql server agent.

Create a procedure in which what query to be updated.

Include this procedure in a job and create a schedule for every half an hour.

Its better to use a procedure inside the job. Since updations can only be done in a procedure itself.
 
Share this answer
 
Comments
Arunprasath Natarajan 6-Jun-12 3:47am    
Sorry to say. I dont know how to create a Job using sql server agent.
Can you give me flow please.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900