Advertisement
Intermediate SQL Server, SQL Server Agent & Job Scheduling

How do you configure a job step to automatically retry if it fails, rather than immediately marking the entire job as failed?

Short answer

You set the retry attempts and retry interval properties on a specific job step, telling SQL Server Agent to automatically attempt that step again a defined number of times, waiting a specified number of minutes between attempts, before finally marking it as failed if all retry…

Save SQL Server mock interview
Advertisement
AModel answer
You set the retry attempts and retry interval properties on a specific job step, telling SQL Server Agent to automatically attempt that step again a defined number of times, waiting a specified number of minutes between attempts, before finally marking it as failed if all retry attempts are unsuccessful.
EXEC msdb.dbo.sp_update_jobstep
  @job_name = 'DataSync',
  @step_id = 1,
  @retry_attempts = 3,
  @retry_interval = 5;
Real-world example
A data synchronization job automatically retries up to three times with a five minute delay between attempts if it initially fails due to a temporary network issue, often succeeding on a retry without requiring any manual intervention.
Likely follow-ups
  • What kinds of failures are good candidates for automatic retry versus immediate alerting?
  • How do you view how many times a step actually retried during a specific run?
Related topics