olahallengren/sql-server-maintenance-solution

SQL Server Maintenance Solution

TSQL

3,512

647 commits

updated Sep 12, 2026

See the code

README

SQL Server Maintenance Solution

licence badge stars badge forks badge issues badge bug report badge SQL Server bug badge feature request badge

Getting Started

Download the script for your platform:

  • MaintenanceSolution.sql: SQL Server 2017, SQL Server 2019, SQL Server 2022, SQL Server 2025, and Azure SQL Managed Instance. This script creates all the objects and jobs that you need.
  • MaintenanceSolutionAzureSQLDatabase.sql: Azure SQL Database. This script creates the objects for integrity check and index and statistics maintenance.

You can also download the objects as separate scripts:

Note that you always need CommandExecute; DatabaseBackup, DatabaseIntegrityCheck, and IndexOptimize use 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.

You can verify the scripts against the SHA-256 checksums in SHA256SUMS.txt.

Documentation

sqlserver

olahallengren/sql-server-maintenance-solution

SQL Server Maintenance Solution

TSQL

3,512

647 commits

updated Sep 12, 2026

See the code

README

SQL Server Maintenance Solution

licence badge stars badge forks badge issues badge bug report badge SQL Server bug badge feature request badge

Getting Started

Download the script for your platform:

  • MaintenanceSolution.sql: SQL Server 2017, SQL Server 2019, SQL Server 2022, SQL Server 2025, and Azure SQL Managed Instance. This script creates all the objects and jobs that you need.
  • MaintenanceSolutionAzureSQLDatabase.sql: Azure SQL Database. This script creates the objects for integrity check and index and statistics maintenance.

You can also download the objects as separate scripts:

Note that you always need CommandExecute; DatabaseBackup, DatabaseIntegrityCheck, and IndexOptimize use 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.

You can verify the scripts against the SHA-256 checksums in SHA256SUMS.txt.

Documentation

sqlserver

Significant stargazers

Kevin

29 followers · starred Jul 2020

Drew Skwiers-Koballa

116 followers · starred Nov 2018

Jackie Ng

117 followers · starred Apr 2019

Chrissy LeMaire

1,023 followers · starred Feb 2019