how to execute data base function daily once automatically
how to execute data base function daily once automatically using serveces(windows/web)
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Munesh SharmaPosted Oct 15, 2014, 3:01 AM
SELECT GETDATE() --your query to run
raiserror('',0,1) with nowait --to flush the buffer
waitfor delay '00:00:10' --pause for 10 seconds
GO 5 --loop 5 timesit will run the query 5 times,
pausing for 10 seconds between each run
output:
Beginning execution loop -----------------------
2011-03-25 11:03:57.640 (1 row(s) affected)
-----------------------
2011-03-25 11:04:07.640 (1 row(s) affected)
-----------------------
2011-03-25 11:04:17.640 (1 row(s) affected)
-----------------------
2011-03-25 11:04:27.640 (1 row(s) affected) -----------------------
2011-03-25 11:04:37.640 (1 row(s) affected)
Batch execution completed 5 times.
Munesh SharmaPosted Oct 15, 2014, 3:00 AM
Expand the SQL Server Agent node and right click the Jobs node in SQL Server Agent and select
'New Job'In the
'New Job'window enter the name of the job and a description on the'General'tab.Select
'Steps'on the left hand side of the window and click'New'at the bottom.In the
'Steps'window enter a step name and select the database you want the query to run against.Paste in the T-SQL command you want to run into the Command window and click
'OK'.Click on the
'Schedule'menu on the left of the New Job window and enter the schedule information (e.g. daily and a time).Click
'OK'- and that should be it.(There are of course other options you can add - but I would say that is the bare minimum you need to get a job set up and scheduled)