Skip to main content

SQL Server Agent Jobs

SQL Server Agent is the built-in job scheduler for SQL Server. It's available on SQL Server on VMs and SQL Managed Instance — but NOT on Azure SQL Database.

Where SQL Agent Works

PlatformSQL Agent Available?Alternative
SQL Server on VM✅ Full access
SQL Managed Instance✅ Full access
Azure SQL Database❌ Not availableElastic Jobs, Azure Automation

How SQL Agent Works

SQL Agent uses a 3-component model:

ComponentWhat It Does
JobA container with one or more steps that execute in order
StepA single unit of work (T-SQL, PowerShell, SSIS, OS command)
ScheduleWhen the job runs (recurring, one-time, on-demand)

Job Step Types

Step TypeUse CaseExample
T-SQLDatabase operationsIndex rebuild, statistics update, data cleanup
PowerShellOS + Azure operationsSend email, call REST API, file operations
SSIS PackageETL workflowsData import/export between systems
OS Command (CmdExec)Shell scriptsRun batch files, external programs
ReplicationLog reader, snapshot, distributionTransactional replication maintenance
🎯 Exam Focus

DP-300 key fact: SQL Agent jobs run under the context of the SQL Server Agent service account unless you configure a proxy with specific credentials. For security, always use proxies with least-privilege credentials for non-T-SQL steps.

Job Scheduling Options

Schedule TypeExample
RecurringEvery day at 2:00 AM, every Sunday at midnight
One-timeRun once on March 15 at 10:00 AM
CPU IdleRun when CPU is idle (useful for low-priority maintenance)
On-demandManual execution only
On Agent StartRun when SQL Agent service starts

Notifications and Alerts

SQL Agent can notify you when jobs succeed or fail:

Notification MethodHow It Works
Database MailSend email via SMTP (requires Database Mail profile)
OperatorA named recipient (email, pager, net send)
Event LogWrite to Windows Event Log
SQL Agent AlertTrigger another job or notification on error/severity

Alert Types

Alert TypeTriggers OnExample
SQL Server ErrorSpecific error numberError 823 (I/O error)
Severity LevelError severity 17-25Severity 19+ (fatal resource errors)
Performance ConditionCounter thresholdCPU > 90% for 5 minutes
WMI EventWMI query matchDeadlock detected
🏢 Real-World DBA Note

Best practice: Always create alerts for severity 17-25 errors. These are fatal errors (resource issues, hardware errors, corruption) that need immediate DBA attention. Configure Database Mail + an operator to get email notifications.

Common Maintenance Jobs Every DBA Should Create

JobFrequencyWhat It Does
Index Rebuild/ReorganizeWeeklyDefragment indexes (rebuild > 30%, reorganize 10-30%)
Update StatisticsDailyKeep query optimizer statistics current
DBCC CHECKDBWeeklyCheck database integrity for corruption
Backup CleanupDailyDelete old backup files beyond retention
Cycle Error LogWeeklysp_cycle_errorlog — prevents log from growing too large
Purge Job HistoryMonthlyClean old job history to prevent msdb growth
🎯 Exam Focus

Ola Hallengren's Maintenance Solution is the industry standard for SQL Server maintenance jobs. It creates optimized index, statistics, backup, and integrity check jobs. Know this exists for the exam — it's referenced in Microsoft documentation.

SQL Agent on Managed Instance — Differences

MI supports SQL Agent but with some differences from on-VM:

FeatureSQL on VMSQL MI
T-SQL steps
PowerShell steps❌ (use Azure Automation)
SSIS steps❌ (use ADF SSIS IR)
CmdExec steps
Database Mail
Operators
ProxiesLimited
Multi-server jobs
⚠️ Watch Out

MI limitation: SQL Agent on MI only supports T-SQL job steps. No PowerShell, CmdExec, or SSIS steps. For non-T-SQL automation on MI, use Azure Automation Runbooks or Azure Logic Apps.

Job Monitoring

MethodWhat It Shows
Job Activity MonitorCurrent status of all jobs (SSMS)
msdb.dbo.sysjobhistoryHistorical job execution results
sp_help_jobactivityCurrently running jobs
SQL Agent Error LogAgent-level errors and warnings
Azure Monitor (MI)Agent job metrics in Azure Portal

Flashcards

Is SQL Server Agent available on Azure SQL Database?
Click to reveal answer
No. SQL Agent is only available on SQL Server on VMs and SQL Managed Instance. For Azure SQL DB, use Elastic Jobs or Azure Automation.
1 / 5

Quiz

Q1/5
0 correct
You need to schedule a nightly index maintenance job on Azure SQL Managed Instance. Which step type should you use?