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.
-
1Are you looking for Azure Automation? https://azure.microsoft.com/en-en/blog/azure-automation-your-sql-agent-in-the-cloud/ – Alex Jan 20 '17 at 17:54
2 Answers
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)
https://docs.microsoft.com/en-us/azure/app-service-web/web-sites-create-web-jobs
Azure Automation
Basically allows you to run anything that can be executed with PowerShell cmdlets on a schedule, continuous or on-demand way.
https://docs.microsoft.com/en-us/azure/automation/automation-intro
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
![](../../users/profiles/218644.webp)
- 3,804
- 1
- 11
- 18
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