'How can I schedule a SQL job in Microsoft Azure SQL Database?

I have one SQL Agent maintenance job which checks the index fragmentation within a database and rebuilds indexes if required.

This is running well in my test server (Microsoft Sql Server 2012). But my production server is in Azure. Now I want to schedule that job to Azure.

SQL Agent does not exist in Azure SQL Database so how can I schedule a SQL job in Azure DB?



Solution 1:[1]

Since this question was first asked, there is now another alternative to handle this problem:
Azure Functions

Here are a couple of examples that could easily be modified to call a stored procedure that rebuilds your indexes

Also see

A few things to keep in mind with Azure functions

Edit September 5, 2021 to add additional information

It should be noted that if you need SQL Agent, you have another option now. I would suggest reading up on Azure SQL Managed Instances. You can see a comparison of Azure SQL to Azure SQL Managed instance here in the Microsoft Documentation. With Azure SQL Managed Instances, your transition to the cloud could be a lot simpler since a lot of the on-premise features you are used to are already there (including SQL Server Agent, DB Mail, etc.).

Solution 2:[2]

This feature has been rejected by Microsoft, see here.

To quote the post:

Today in Azure there are several alternatives,

  1. SQL Database Elastic Jobs https://docs.microsoft.com/en-us/azure/azure-sql/database/elastic-jobs-overview

  2. The Azure job scheduler http://www.windowsazure.com/en-us/services/scheduler/

  3. The new preview of Azure Automation http://azure.microsoft.com/en-us/services/automation/.

  4. SQL Server in a VM

Option 1 requires an additional dedicated cloud service, which increases cost. Option 2 is free (I think) as long as you don't run more than once per hour.

Solution 3:[3]

Azure SQL does not support sql jobs. From documentation:

Microsoft Azure SQL Database does not support SQL Server Agent or jobs. You can, however, run SQL Server Agent on your on-premise SQL Server and connect to Microsoft Azure SQL Database.

WebJobs: If you have a website you can create webjob and run it on schedule. See more here

Other alternatives - Scheduling job on SQL Azure

Solution 4:[4]

Another option is rovergo, a service that allows you to schedule sql jobs with a cron expression. This is nice because you don't have to create a web job or azure function. You can simply schedule a sql script.

(I'm a developer on rovergo)

Solution 5:[5]

You can use Azure automation to schedule jobs on an Azure-DB like the on premise SQL Agent.

See https://azure.microsoft.com/nl-nl/blog/azure-automation-your-sql-agent-in-the-cloud/ for more information.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1
Solution 2
Solution 3 b2zw2a
Solution 4 jrummell
Solution 5 Rolf Schouteten