I'm looking for a way to set up a nightly job that will run a small SQL Script, to rebuild fragmented indexes on an Azure SQL database. Resources I have found online seem to be either dated, or involve setting up the job on a local machine.


Two easy options:

Web Jobs

You can run programs or scripts in WebJobs in Azure App Service web app. Any script written in The following file types are accepted:

  • .cmd, .bat, .exe (using windows cmd)
  • .ps1 (using powershell)
  • .sh (using bash)
  • .php (using php)
  • .py (using python)
  • .js (using node)
  • .jar (using java)


Azure Automation

Basically allows you to run anything that can be executed with PowerShell cmdlets on a schedule, continuous or on-demand way.


Azure Automation comes with 500min. free. If you need assistance setting up the basics here's a good setup guide.

Getting Started Querying your Azure SQL Database in PowerShell



To perform scheduled tasks on Azure, in addition to Web Jobs and Automation Accounts as Bruno mentioned, you can also use Azure Functions:

Azure Functions is a solution for easily running small pieces of code, or "functions," in the cloud. You can use your development language of choice, such as C#, F#, Node.js, Python or PHP.


Azure Functions supports triggers, which are ways to start execution of your code.

TimerTrigger - executes cleanup or other batch tasks on a predefined schedule.

MSDN: Introduction to Azure Functions

Here is a good example how to create a scheduled SQL task with Azure Functions on MSDN: Use Azure Functions to perform a scheduled clean-up task

Your Answer

By clicking "Post Your Answer", you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.