Overview of DatabaseIntegrityCheck
mainDatabaseIntegrityCheck is the stored procedure provided by the SQL Server Maintenance Solution specifically designed to check the integrity of SQL Server databases.repository·main·Indexed 25 days ago
https://github.com/olahallengren/sql-server-maintenance-solutionA comprehensive SQL Server maintenance solution providing automated scripts for database backups, integrity checks, and index/statistics maintenance. Key components include DatabaseBackup for flexible backup operations (supporting local, network, Azure Blob Storage, and S3), IndexOptimize for index and statistics management, and DatabaseIntegrityCheck. The solution includes support for encryption, compression, and parallel processing via Queue scripts.
DatabaseIntegrityCheck is the stored procedure provided by the SQL Server Maintenance Solution specifically designed to check the integrity of SQL Server databases.IndexOptimize stored procedure is the primary tool within the SQL Server Maintenance Solution for rebuilding and reorganizing indexes and updating statistics.dbo.DatabaseIntegrityCheck stored procedure from T-SQL job steps. Use the MaintenanceSolution.sql script to automatically create the necessary SQL Server Agent jobs.Choose the appropriate script based on your SQL Server platform:
MaintenanceSolution.sql. This script creates all necessary objects and jobs.MaintenanceSolutionAzureSQLDatabase.sql. This script creates objects for integrity checks and index/statistics maintenance.If you do not want the full solution, you can install individual components as separate scripts.
Important Dependencies:
CommandExecute is a required dependency for DatabaseBackup, DatabaseIntegrityCheck, and IndexOptimize.DatabaseBackup, DatabaseIntegrityCheck, or IndexOptimize, you must also update CommandExecute.CommandLog is required if you intend to use the option to log commands to a table.Queue.sql and QueueDatabase.sql are used for processing databases in parallel.Available 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/reorganize indexes and update statistics.CommandExecute.sql: Stored procedure to execute and log commands.CommandLog.sql: Table to log commands.Queue.sql: Table for parallel processing.QueueDatabase.sql: Table for parallel processing.DatabaseBackup stored procedure is the primary tool in the SQL Server Maintenance Solution for performing database backups. It supports various parameters for database selection, directory management, backup types, verification, and cleanup.dbo.DatabaseBackup, you can use the MaintenanceSolution.sql script to create the necessary SQL Server Agent jobs. These jobs can then be managed and scheduled via T-SQL job steps.Enhance dbo.IndexOptimize execution with the following options:
@SortInTempdb = 'Y' to perform sort operations in tempdb and @MaxDOP = 0 to use all available CPUs.@PartitionLevel = 'Y' to maintain partitioned indexes at the partition level.@TimeLimit = <seconds> to ensure no new commands are executed after a specific duration.@LogToTable = 'Y' to record maintenance results in a table.-- Example: Rebuild indexes with tempdb sorting, max DOP, and a 1-hour time limit
EXECUTE dbo.IndexOptimize
@Databases = 'USER_DATABASES',
@FragmentationLow = NULL,
@FragmentationMedium = 'INDEX_REORGANIZE,INDEX_REBUILD_ONLINE,INDEX_REBUILD_OFFLINE',
@FragmentationHigh = 'INDEX_REBUILD_ONLINE,INDEX_REBUILD_OFFLINE',
@FragmentationLevel1 = 5,
@FragmentationLevel2 = 30,
@SortInTempdb = 'Y',
@MaxDOP = 0,
@TimeLimit = 3600To use the DatabaseIntegrityCheck stored procedure, you must first install the maintenance solution objects. Choose the script corresponding to your SQL Server platform:
MaintenanceSolution.sql. This script creates all necessary objects and jobs.MaintenanceSolutionAzureSQLDatabase.sql. This script creates objects for integrity check and index/statistics maintenance.Control how backup files are organized using @DirectoryStructure and @FileName. You can use tokens like {ServerName}, {InstanceName}, {DatabaseName}, {BackupType}, and {Year}{Month}{Day} to create dynamic paths. Setting these to NULL will prevent the creation of sub-directories.
-- Custom directory structure without server/instance names
EXECUTE dbo.DatabaseBackup
@Databases = 'USER_DATABASES',
@Directory = 'C:\Backup',
@BackupType = 'FULL',
@DirectoryStructure = '{DatabaseName}{DirectorySeparator}{BackupType}_{Partial}_{CopyOnly}',
@AvailabilityGroupDirectoryStructure = '{DatabaseName}{DirectorySeparator}{BackupType}_{Partial}_{CopyOnly}'Use the @Indexes parameter to control which indexes are processed:
'DatabaseName.SchemaName.TableName').'ALL_INDEXES, -DatabaseName.SchemaName.TableName' to process all indexes except the one specified with a minus sign.-- Rebuild all indexes except for a specific table
EXECUTE dbo.IndexOptimize
@Databases = 'USER_DATABASES',
@FragmentationLow = NULL,
@FragmentationMedium = 'INDEX_REORGANIZE,INDEX_REBUILD_ONLINE,INDEX_REBUILD_OFFLINE',
@FragmentationHigh = 'INDEX_REBUILD_ONLINE,INDEX_REBUILD_OFFLINE',
@FragmentationLevel1 = 5,
@FragmentationLevel2 = 30,
@Indexes = 'ALL_INDEXES, -AdventureWorks.Production.Product'You can distribute backups across multiple network shares by providing a comma-separated list to @Directory and specifying the number of files via @NumberOfFiles.
EXECUTE dbo.DatabaseBackup
@Databases = 'USER_DATABASES',
@Directory = '\\Server1\Backup, \\Server2\Backup, \\Server3\Backup, \\Server4\Backup',
@BackupType = 'FULL',
@Verify = 'Y',
@NumberOfFiles = 4