Skip to main content

Elastic Jobs & Azure Automation

Since Azure SQL Database doesn't have SQL Agent, Microsoft provides two cloud-native automation services: Elastic Jobs (for T-SQL across databases) and Azure Automation (for PowerShell/Python runbooks).

Elastic Jobs — SQL Agent for Azure SQL Database

Elastic Jobs let you run T-SQL scripts across one or more Azure SQL databases on a schedule — the PaaS equivalent of SQL Agent.

Architecture

ComponentWhat It Is
Job AgentAzure resource that hosts and executes jobs (requires a dedicated "job database")
Job DatabaseAn Azure SQL DB that stores job definitions, history, and state
Target GroupWhich databases to run against (single DB, elastic pool, shard map, or list)
JobContainer with steps (T-SQL only)
Job CredentialDatabase-scoped credential for authentication

When to Use Elastic Jobs

ScenarioElastic Jobs?
Run T-SQL across multiple Azure SQL DBs✅ Best choice
Index maintenance across tenant databases
Schema changes across all databases
PowerShell automation❌ Use Azure Automation
Cross-service orchestration❌ Use Logic Apps
Single database scheduled T-SQL✅ (simpler alternatives exist)
🎯 Exam Focus

DP-300 key fact: Elastic Jobs require a dedicated Azure SQL Database as the job database. This is an additional cost. The job agent is a separate Azure resource that you deploy alongside it.

Target Group Types

Target TypeDescription
Single DatabaseOne specific database
Elastic PoolAll databases in a pool
Shard MapAll shards in a shard map
Database ListCustom list of databases across servers
Server (all DBs)All user databases on a logical server

Elastic Jobs vs SQL Agent

FeatureSQL AgentElastic Jobs
PlatformVM + MIAzure SQL DB
Step typesT-SQL, PS, SSIS, CmdExecT-SQL only
Multi-databaseMulti-server adminTarget groups
SchedulingBuilt-in schedulerBuilt-in scheduler
CostIncludedJob agent + job DB cost
NotificationsDatabase Mail + operatorsAzure Monitor alerts
HistorymsdbJob database

Azure Automation — PowerShell/Python in the Cloud

Azure Automation runs PowerShell or Python scripts (runbooks) on a schedule or on-demand — no VM required.

Key Concepts

ComponentWhat It Does
Automation AccountContainer for runbooks, schedules, credentials
RunbookPowerShell or Python script
ScheduleWhen the runbook runs
Managed IdentityAuthentication to Azure resources (no passwords)
Hybrid Runbook WorkerRun runbooks on-premises or on specific VMs
WebhookHTTP endpoint to trigger runbooks externally

Common DBA Runbooks

Runbook PurposeWhat It Does
Scale up/downChange Azure SQL vCores on schedule (scale up for batch, down at night)
Pause ServerlessForce auto-pause of serverless databases during off-hours
Index maintenanceRun Ola Hallengren scripts across multiple databases
Backup to BlobCopy backups to secondary storage
Alert responseAuto-remediate when an alert fires
Compliance checkVerify security settings across databases
🎯 Exam Focus

Azure Automation uses Managed Identity for authentication — no stored passwords or connection strings. Always use System Assigned Managed Identity and grant it the minimum required Azure RBAC role (e.g., SQL DB Contributor for scaling operations).

Azure Automation vs Elastic Jobs

AspectElastic JobsAzure Automation
Best forT-SQL across DBsPowerShell/Python automation
Script typesT-SQL onlyPowerShell, Python
Azure resource mgmt✅ (scale, configure, deploy)
Cross-service✅ (any Azure resource)
CostJob agent + DBPer-minute execution
AuthenticationDB credentialManaged Identity
On-prem support✅ (Hybrid Worker)
🏢 Real-World DBA Note

Common pattern: Use Elastic Jobs for database-level T-SQL automation (index maintenance, schema sync) and Azure Automation for infrastructure-level PowerShell automation (scaling, alerting, compliance). They complement each other — they're not competitors.

Azure Logic Apps — Visual Workflow Automation

Logic Apps provide visual, low-code workflow automation with 400+ connectors:

Use CaseWhy Logic Apps
Email on job failureConnect SQL → Office 365 → send email
Approval workflowsSchema change requires manager approval
Multi-service orchestrationSQL → Event Hub → Function → Teams
Scheduled data syncTimer → query SQL → post to API

Logic Apps vs Azure Automation

AspectLogic AppsAzure Automation
StyleVisual designer (low-code)Script (code-first)
Best forWorkflow orchestrationScript execution
Connectors400+ built-inManual REST/SDK calls
CostPer-actionPer-minute
Complex logicClunky for complex codeNatural for scripts

Azure Functions — Timer-Triggered Automation

For developers who prefer code, Azure Functions with a Timer Trigger replace cron jobs:

FeatureDetail
LanguagesC#, Python, Java, JavaScript, PowerShell
TriggerCRON expression (e.g., 0 */5 * * * * for every 5 min)
ScalingAuto-scales (or Consumption plan = pay-per-execution)
Best forCustom automation logic that doesn't fit Automation Runbooks

Flashcards

What is required to use Elastic Jobs?
Click to reveal answer
A dedicated Azure SQL Database as the 'job database' plus a Job Agent resource. Both have separate costs.
1 / 5

Quiz

Q1/5
0 correct
You need to run an index maintenance T-SQL script across 50 databases in an Azure SQL Elastic Pool every weekend. What should you use?