If you’re already running Ola Hallengren’s maintenance solution, this framework won’t replace it, but the approach might still be useful: 3 small, readable T-SQL generator scripts that build the same category of scheduled job framework, full and log backups, backup cleanup, DBCC CHECKDB, index and statistics maintenance, job/backup history cleanup, and error log cycling, as plain sp_add_job / sp_add_jobstep DDL you can review end to end before you ever run it.
That readability is the point. Every job step is copy/paste T-SQL or PowerShell you can review line by line, not a call into a larger set of procedures. 8 jobs come out of 3 generator scripts, each covered on its own page below.
Why a Generated, Readable Framework Matters
- A maintenance framework you can’t read is a maintenance framework you can’t fully trust, and most DBAs run someone else’s maintenance procedures without ever fully reading them
- Generator scripts separate “decide the parameters” from “run the DDL”: you review the exact
sp_add_jobcalls before anything touchesmsdb - Every job step is copy/paste T-SQL or PowerShell, not a black-box procedure call, when something needs troubleshooting during an incident, you’re reading the actual command, not stepping into unfamiliar procedure code
- Idempotent generation: every job starts with
IF EXISTS ... sp_delete_jobbefore recreating it, so re-running a generator after changing a parameter cleanly replaces the old job rather than leaving duplicates behind
Start Here
The Framework, Grouped by What Each Generator Builds
💾 Backup Jobs
DBA - Backup - FULL
Full backup, all online user databases · Daily, 02:00
DBA - Backup - LOG
Log backups, FULL/BULK_LOGGED only · Every 15 minutes
DBA - Backup - Cleanup
Deletes backup files past retention · Daily, 03:00
🛡️ Integrity and Housekeeping
DBA - Integrity Check
DBCC CHECKDB, every online database · Weekly, Sat 02:00
DBA - History Cleanup
Purges backup/job history, mail log · Weekly, Sun 03:00
DBA - Cycle Error Log
Rotates the SQL Server error log · Weekly, Mon 00:00
⚡ Index and Statistics
DBA - Index Maintenance
Rebuilds/reorganizes fragmented indexes · Weekly, Sun 01:00
DBA - Statistics Update
Updates stats on tables with modified rows · Weekly, Sat 23:00
How They Fit Together
A sensible deployment order for a new instance:
Best Practices Across the Series
- Review the generated DDL before running it. Every script only produces text; nothing touches
msdbuntil you execute the output yourself. - Regenerate rather than hand-edit: change a parameter and re-run, the
IF EXISTS ... sp_delete_jobpattern replaces cleanly rather than duplicating. - Don’t schedule
DBA - Integrity CheckorDBA - Index Maintenanceto overlap with backups or each other on an instance under memory pressure, both jobs assume they’ll get the memory grant they ask for, and that assumption fails loudly on a shared or resource-constrained box. - After any maintenance job fails with an error cascade mentioning
9001,3314, or3908, checksys.databases.state_descfor that database before assuming corruption, SQL Server’s own crash recovery is usually the actual story. - Confirm job success periodically with Get Maintenance Job Status, not just on the day you first deployed.
Frequently Asked Questions
Why generate jobs instead of creating them by hand?
Consistency across servers. Hand-built jobs drift, and the differences only surface during an incident. Generated jobs are identical everywhere and can be reviewed as script before they run.
Does this replace the standard maintenance solution?
No, and it is not trying to. The established scripts are the standard for the work itself; this is about the scaffolding around them being consistent and actually scheduled.
What order should maintenance run in?
Integrity checks before anything that rewrites data, backups where they fit the recovery promise, and index work in the quietest window. Running index maintenance before a full backup mostly guarantees a large backup of freshly rewritten pages.
Summary
3 generator scripts, 8 readable jobs: start with backups, add integrity and housekeeping, finish with index maintenance, and check back with Get Maintenance Job Status to confirm they keep succeeding on schedule, not just on day one. What each job does, and what to watch for when it runs, is on that job’s own page.
Related
- SQL Agent and Jobs
- Index Maintenance
- DBA Scripts: Get Last DBCC CHECKDB
- DBA Scripts: Get Backup Coverage
- DBA Scripts: Get SQL Agent Job Failure Summary
- SQL Agent Job Failed: Finding the Step That Actually Broke
- DBCC CHECKDB Found Corruption: What to Actually Do Next
- BACKUP LOG Cannot Be Performed Because There Is No Current Database Backup (Error 4214)
- msdb Is Growing: Purge Backup, Job and Mail History Safely
- DBA Scripts: The Complete Guide
Leave a Reply