Download MaintenanceSolution.sql. This script creates all the objects and jobs that you need.
You can also download the objects as separate scripts:
- DatabaseBackup.sql: Stored procedure to back up databases
- DatabaseIntegrityCheck.sql: Stored procedure to check the integrity of databases
- IndexOptimize.sql: Stored procedure to rebuild and reorganize indexes and update statistics
- CommandExecute.sql: Stored procedure to execute and log commands
- CommandLog.sql: Table to log commands
- Queue.sql: Table for processing databases in parallel
- QueueDatabase.sql: Table for processing databases in parallel
Note that you always need CommandExecute; DatabaseBackup, DatabaseIntegrityCheck, and IndexOptimize are using it.
When you update DatabaseBackup, DatabaseIntegrityCheck, or IndexOptimize you should also update CommandExecute.
You need CommandLog if you are going to use the option to log commands to a table.
Supported versions: SQL Server 2005, SQL Server 2008, SQL Server 2008 R2, SQL Server 2012, SQL Server 2014, SQL Server 2016, SQL Server 2017, Azure SQL Database, and Azure SQL Database Managed Instance.
The SQL Server Maintenance Solution is available on GitHub.
Script to check version timestamps: VersionCheck.sql
Sign up for the newsletter to be alerted about updates to the solution.