makitocode
makitocode

Reputation: 948

how to periodically run sql query in azure?

I know some jobs can be run periodically or querys a database. how achievement run this code every "x" days in an azure sql table?

DELETE FROM [MobileServiceExtra].[ACTIVITY]
WHERE [NewsItemDate] < GETDATE()- 5

Upvotes: 3

Views: 2664

Answers (7)

Tadas Bublys
Tadas Bublys

Reputation: 85

You can use Azure Automation Runbook. Example here. I use this for daily table truncation, works perfect for me.

Upvotes: 0

Cotega
Cotega

Reputation: 339

If you are open to using a service for this, we offer this functionality within our Cotega service. The way that it works is that you create a stored procedure within your database to execute this code and simply set up a schedule for how often you want it to run.

Upvotes: 0

Mohit chhabra
Mohit chhabra

Reputation: 123

You can use windows azure scheduler preview right now http://www.windowsazure.com/en-us/services/scheduler/.

Do check out the pricing,right now they are charging $10/month and it will be increased to $20/month once the preview period is over.

You can also try aditi scheduler http://www.aditicloud.com/ as well,the only issue with aditi scheduler is its available in azure store ( which is not accessible in many countries) and you have to use your credit card again to consume it.

Hope it helps!

Thanks.

Mohit Chhabra

Upvotes: 0

Rikalous
Rikalous

Reputation: 4564

Windows Azure Scheduler is a new service that has just gone into preview - http://www.windowsazure.com/en-us/services/scheduler/. This looks like an all-purpose service to do this kind of thing. I don't expect SQL on Azure will ever support Agent.

Upvotes: 4

Sandrino Di Mattia
Sandrino Di Mattia

Reputation: 24895

It looks like you're using Mobile Services. Mobile Services comes with a Scheduler which can connect to your database and do whatever you need in a recurring schedule.

More information:
Build your own SQL Server Agent for Windows Azure SQL Database with the Scheduler

You would end up writing a little bit of javascript in the Scheduler which will run your SQL statement:

function Call_sp_ClearOldLogs() {
    console.log("Executing sp_ClearOldLogs...");
    mssql.query('EXEC dbo.sp_ClearOldLogs', {
        success: function(results) {
        console.log("Finished executing sp_ClearOldLogs.");
        }
    });
}

Upvotes: 1

GraemeMiller
GraemeMiller

Reputation: 12253

We use Quartz.Net within our Azure combined web and worker role.

You can see my colleagues post about it here

Upvotes: 1

jpw
jpw

Reputation: 44871

It would seem that Azure does not support SQL Server Agent and scheduling of jobs.

According to a series of blog posts on MSDN you can however use the Windows Azure Worker role to schedule custom jobs (that run SQL):

I Miss You SQL Server Agent: Part 1

I haven't tried this, so I can't tell you if it's a viable solution.

Upvotes: 1

Related Questions