Best way to Schedule Sql job in Microsoft Azure? [

2019-01-23 04:55发布

问题:

I have one sql job which actually checks fragmentation % in db of all the indexes and Rebuilds indexes if required. Which is running well in my Testing server Microsoft Sql Server 2012. But my production server is in Azure. Now I want to schedule that job to Azure. How can I schedule a Sql Job in Azure Db? I am new to Azure.

回答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

  • Create a function in Azure that is triggered by a timer
  • Use Azure Functions to connect to an Azure SQL Database

Also see

  • How to maintain Azure SQL Indexes and Statistics - this page has an example stored procedure for rebuilding your indexes that you can download.
  • Reorganize and Rebuild Indexes

A few things to keep in mind with Azure functions

  • They are built on top of Azure Web Jobs SDK and offer additional functionality
  • There are two different pricing models:
    • App Service plan (attach it to an existing plan)
      • Predictable cost model
      • It puts extra load on the same VM used by your web site
    • Consumption plan
      • You get some free processing every month
      • The default maximum run time is 5 minutes to prevent billing problems, but it can be changed via the host.json file.


回答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 http://azure.microsoft.com/en-us/documentation/articles/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.



回答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



回答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)