Use it when scheduled database jobs fail or do not run.
SQL Server Agent Jobs
SQL Server Agent schedules and runs jobs (backups, maintenance, ETL) with steps, schedules, alerts and operators.
1. Agent running: SELECT status_desc FROM sys.dm_server_services;.
2. History: EXEC msdb.dbo.sp_help_jobhistory @job_name='<job>';.
3. Failed step message.
4. Owner/proxy permissions.
5. Notifications on failure.
schedule → job → steps run as owner/proxy → history
Context & applicabilityCommon mistakes · platform/version boundaries
Operational reference
Fast context before you go deeper.
Verification & Troubleshooting
Start with the observed symptom, prove the nearest boundary, and move outward only when the current state is understood.
Use the operational verification above to establish the expected state.
Capture the concrete output, symptom, packet, log or counter before changing anything.
Step 1 How to verify Verify boundary
Check the last run outcome and duration of critical jobs daily. Configure failure notifications to an operator.
Step 2 Checking jobs Verify boundary
EXEC msdb.dbo.sp_help_job @job_name = N'Nightly backup';
SELECT j.name, h.run_date, h.run_time, h.run_status, h.message
FROM msdb.dbo.sysjobhistory h JOIN msdb.dbo.sysjobs j ON j.job_id = h.job_id
WHERE h.step_id = 0 ORDER BY h.run_date DESC, h.run_time DESC;
The SQL Server Agent service must be running (not available in Express). Configure Database Mail and operators for failure notifications; Ola Hallengren's maintenance solution is a common standard for backups and index/statistics jobs.
Step 3 Common failures Narrow the fault
Agent service set to manual start stops all jobs after a reboot. A step writing to a network share fails because the service account lacks access. Express Edition has no Agent.
Agent service must run (not available in Express). Check job history for step errors and the proxy/credential used. Configure notifications for failures.
SELECT status_desc FROM sys.dm_server_services;— first check for this topicpsql -c "SELECT now(), version();"— PostgreSQL reachable and versionmysql -e "SELECT NOW(), VERSION();"— MariaDB/MySQL reachable and versionsqlcmd -S <server> -Q "SELECT @@VERSION"— SQL Server reachable and version
ReferenceWhat it is1 section · depth on demand
How it works
Agent stores jobs, steps and schedules in msdb. Each step can be T-SQL, PowerShell or an SSIS package and has success and failure actions. Operators and alerts send notifications.
ReferenceImportant terms & boundaries2 sections · depth on demand
In depth
Parts of a job
| Part | What to set |
|---|---|
| Owner | A dedicated login (or sa), not a person who may leave |
| Steps | T-SQL, PowerShell, CmdExec, SSIS; each with On success / On failure action and retry count |
| Proxy | Credential for non-T-SQL steps that need access outside SQL Server (shares, other servers) |
| Schedule | Shared schedules can drive several jobs |
| Notifications | Operator e-mail via Database Mail on failure |
The Agent service is often installed with manual start; set it to Automatic or every job silently stops after a reboot. On Linux and Azure SQL Managed Instance the feature set differs.
Worked check — failed or overrunning jobs in the last 24 hours
SELECT j.name, h.step_id, h.step_name,
msdb.dbo.agent_datetime(h.run_date, h.run_time) AS started,
h.run_duration, h.run_status, LEFT(h.message, 200) AS message
FROM msdb.dbo.sysjobhistory h
JOIN msdb.dbo.sysjobs j ON j.job_id = h.job_id
WHERE h.run_status <> 1
AND msdb.dbo.agent_datetime(h.run_date, h.run_time) > DATEADD(day, -1, GETDATE())
ORDER BY started DESC;
run_status: 0 failed, 1 succeeded, 2 retry, 3 cancelled. run_duration is encoded as HHMMSS.
Availability groups and failover
Jobs live in msdb, which is not part of an availability group. Create the job on every replica and start each step with a check such as IF sys.fn_hadr_is_primary_replica(N'shop') = 1 so it only does work on the current primary. Logins used by jobs must also exist on every replica.
Keep job history from being truncated too early: the default limits (1000 rows total, 100 per job) can erase the evidence of a failure within hours on a busy server.
Common mistakes
- Agent jobs owned by personal accounts.
Additional reference context Scope · expected state · examples · history · terminology Open only when you need the supporting context
Terms & aliases
Hover a linked term for a quick definition; click it to open its glossary entry. Aliases are other names that find this Topic in search.