Use the Maintenance Plan Wizard
Applies to: SQL Server
This article describes how to create a single or multiserver maintenance plan using the Maintenance Plan Wizard in SQL Server. The Maintenance Plan Wizard creates a maintenance plan that Microsoft SQL Server Agent can run regularly. This allows you to perform various database administration tasks, including backups, database integrity checks, or database statistics updates, at specified intervals.
Limitations and restrictions
To create a multiserver maintenance plan, you must configure a multiserver environment with one master server, and one or more target servers. You must create and maintain the multiserver maintenance plans on the master server. You can view plans on target servers.
Members of the db_ssisadmin and dc_admin roles may be able to elevate their privileges to sysadmin. This elevation of privilege can occur because these roles can modify Integration Services packages; these packages can be executed by SQL Server using the sysadmin security context of SQL Server Agent.
To guard against this elevation of privilege when running maintenance plans, data collection sets, and other Integration Services packages, configure SQL Server Agent jobs that run packages to use a proxy account with limited privileges or only add sysadmin members to the db_ssisadmin and dc_admin roles.
Prerequisites
You must enable Agent XPs Server Configuration Option.
Permissions
To create or manage maintenance plans, you must be a member of the sysadmin fixed server role. Object Explorer only displays the Maintenance Plans node for users who are members of the sysadmin fixed server role.
Use the Maintenance Plan Wizard
Start the Wizard
Expand the server where you want to create your management plan.
Expand the Management folder.
Right-click the Maintenance Plans folder and select Maintenance Plan Wizard.
On the SQL Server Maintenance Plan Wizard page, select Next.
On the Select Plan Properties page:
In the Name box, enter the name of the maintenance plan you're creating.
In the Description box, briefly describe your maintenance plan.
In the Run as list, specify the credential that Microsoft SQL Server Agent uses when executing the maintenance plan.
Select either Separate schedules for each task or Single schedule for the entire plan or no schedule to specify the recurring schedule of the maintenance plan.
Note
If you select Separate schedules for each task, you will need to follow the next step for each task in your maintenance plan.
If you selected Single schedule for the entire plan or no schedule, under Schedule, select Change.
In the New Job Schedule dialog box, in the Name box, enter the job schedule's name.
On the Schedule type list, select the type of schedule:
Start automatically when SQL Server Agent starts
Start whenever the CPUs become idle
Recurring. This is the default selection.
One time
Select or clear the Enabled check box to enable or disable the schedule.
If you select Recurring:
Under Frequency, on the Occurs list, specify the frequency of occurrence:
If you select Daily, in the Recurs every box, enter how often the job schedule repeats in days.
If you select Weekly, in the Recurs every box, enter how often the job schedule repeats in weeks. Select the days of the week on which the job schedule is run.
If you select Monthly, select either Day or The.
If you select Day, enter both the date of the month you want the job schedule to run and how often the job schedule repeats in months. For example, if you want the job schedule to run on the 15th day of the month every other month, select Day and enter "15" in the first box and "2" in the second box. The largest number allowed in the second box is "99".
If you select The, select the specific day of the week within the month that you want the job schedule to run and how often the job schedule repeats in months. For example, if you want the job schedule to run on the last weekday of the month every other month, select Day, select last from the first list and weekday from the second list, and then enter "2" in the last box. You can also select first, second, third, or fourth, as well as specific weekdays (for example: Sunday or Wednesday) from the first two lists. The largest number allowed in the last box is "99".
Under Daily frequency, specify how often the job schedule repeats on the day the job schedule runs:
If you select Occurs once at, enter the specific time of day when the job schedule should run in the Occurs once at box. Enter the hour, minute, and second of the day, as well as AM or PM.
If you select Occurs every, specify how often the job schedule runs during the day chosen under Frequency. For example, if you want the job schedule to repeat every 2 hours during the day that the job schedule is run, select Occurs every, enter "2" in the first box, and then select hour(s) from the list. From this list you can also select minute(s) and second(s). The largest number allowed in the first box is "100".
In the Starting at box, enter the time that the job schedule should start running. In the Ending at box, enter the time that the job schedule should stop repeating. Enter the hour, minute, and second of the day, as well as AM or PM.
Under Duration, in Start date, enter the date that you want the job schedule to start running. Select End date or No end date to indicate when the job schedule should stop running. If you select End date, enter the date that you want to job schedule to stop running.
If you select One Time, under One-time occurrence, in the Date box, enter the date that the job schedule will be run. In the Time box, enter the time that the job schedule will be run. Enter the hour, minute, and second of the day, as well as AM or PM.
Under Summary, in Description, verify that all job schedule settings are correct.
Select OK.
Select Next.
On the Select Target Servers page, select the servers where you want to run the maintenance plan. This page is only visible on SQL Server instances that are configured as master servers.
Note
To create a multiserver maintenance plan, a multiserver environment containing one master server and one or more target servers must be configured, and the local server should be configured as a master server. In multiserver environments, this page displays the (local) master server and all corresponding target servers.
On the Select Maintenance Tasks page, select one or more maintenance tasks to add to the plan. When you have selected all of the necessary tasks, select Next.
Note
The tasks you select here will determine which pages you will need to complete after the Select Maintenance Task Order page below.
On the Select Maintenance Task Order page, select a task and select either Move Up... or Move Down... to change its order of execution. When finished, or if you're satisfied with the current order of tasks, select Next.
Note
If you selected Separate schedules for each task on the Select Plan Properties page above, you will not be able to change the order of the maintenance tasks on this page.
Define Database Check Integrity (CHECKDB)
On the Define Database Check Integrity Task page, choose the database or databases where the allocation and structural integrity of user and system tables and indexes are checked. By running the DBCC CHECKDB
Transact-SQL statement, this task ensures that any integrity problems with the database are reported, thereby allowing them to be addressed later by a system administrator or database owner. For more information, see DBCC CHECKDB (Transact-SQL). When complete, select Next.
The following options are available on this page.
Databases list
Specify the databases affected by this task.
All databases
Generate a maintenance plan that runs this task against all Microsoft SQL Server databases except
tempdb
.System databases
Generate a maintenance plan that runs this task against SQL Server system databases except
tempdb
and user-created databases.All user databases (excluding
master
,model
,msdb
,tempdb
)Generate a maintenance plan that runs this task against all user-created databases. No maintenance tasks are run against the SQL Server system databases.
These databases
Generate a maintenance plan that runs this task against only those databases that are selected. At least one database in the list must be selected if this option is chosen.
Include indexes check box
Check the integrity of all the index pages as well as the table data pages.
Physical only
Limits the check to the integrity of the physical structure of the page, record headers, and the allocation consistency of the database. Using this option may reduce run-time for DBCC CHECKDB on large databases, and is recommended for frequent use on production systems.
Tablock
Causes DBCC CHECKDB to obtain locks instead of using an internal database snapshot. This includes a short-term exclusive (X) lock on the database. Using this option may help DBCC CHECKDB run faster on a database under heavy load, but decreases the concurrency available on the database while DBCC CHECKDB is running.
Define Database Shrink Task
On the Define Shrink Database Task page, create a task that attempts to reduce the size of the selected databases by using the
DBCC SHRINKDATABASE
statement, with either theNOTRUNCATE
orTRUNCATEONLY
option. For more information, see DBCC SHRINKDATABASE (Transact-SQL). When complete, select Next.Warning
Data moved to shrink a file can be scattered to any available location in the file. This causes index fragmentation and can slow the performance of queries that search a range of the index. To eliminate the fragmentation, consider rebuilding the indexes on the file after shrinking.
The following options are available on this page.
Databases list
Specify the databases affected by this task.
All databases
Generate a maintenance plan that runs this task against all Microsoft SQL Server databases except
tempdb
.System databases
Generate a maintenance plan that runs this task against SQL Server system databases except
tempdb
and user-created databases.All user databases (excluding
master
,model
,msdb
,tempdb
)Generate a maintenance plan that runs this task against all user-created databases. No maintenance tasks are run against the SQL Server system databases.
These databases
Generate a maintenance plan that runs this task against only those databases that are selected. At least one database in the list must be selected if this option is chosen.
Shrink database when it grows beyond box
Specify the size in megabytes that causes the task to execute.
Amount of free space to remain after shrink box
Stop shrinking when free space in database files reaches this size (as a percentage).
Retain freed space in database files
The database is condensed to contiguous pages but the pages aren't deallocated, and the database files don't shrink. Use this option if you expect the database to expand again, and you don't want to reallocate space. With this option, the database files don't shrink as much as possible. This uses the NOTRUNCATE option.
Return freed space to operating system
The database is condensed to contiguous pages and the pages are released back to the operating system for use by other programs. This uses the TRUNCATEONLY option. This is the default option.
Define the Index Tasks
On the Define Reorganize Index Task page, select the server or servers where you'll be moving index pages into a more efficient search order. This task uses the
ALTER INDEX ... REORGANIZE
statement. For more information, see ALTER INDEX (Transact-SQL). When complete, select Next.The following options are available on this page.
Databases list
Specify the databases affected by this task.
All databases
Generate a maintenance plan that runs this task against all Microsoft SQL Server databases except
tempdb
.System databases
Generate a maintenance plan that runs this task against SQL Server system databases except
tempdb
and user-created databases.All user databases (excluding
master
,model
,msdb
,tempdb
)Generate a maintenance plan that runs this task against all user-created databases. No maintenance tasks are run against the SQL Server system databases.
These databases
Generate a maintenance plan that runs this task against only those databases that are selected. At least one database in the list must be selected if this option is chosen.
Object list
Limit the Selection list to display tables, views, or both. This list is only available if a single database is chosen from the Databases list above.
Selection list
Specify the tables or indexes affected by this task. Not available when Tables and Views is selected in the Object box.
Compact large objects check box
Deallocate space for tables and views when possible. This option uses
ALTER INDEX ... LOB_COMPACTION = ON
.
On the Define Rebuild Index Task page, select the database or databases where you'll be re-creating multiple indexes. This task uses the
ALTER INDEX ... REBUILD PARTITION
statement. For more information, see ALTER INDEX (Transact-SQL).) When complete, select Next.The following options are available on this page.
Databases list
Specify the databases affected by this task.
All databases
Generate a maintenance plan that runs this task against all Microsoft SQL Server databases except
tempdb
.System databases
Generate a maintenance plan that runs this task against SQL Server system databases except
tempdb
and user-created databases.All user databases (excluding
master
,model
,msdb
,tempdb
)Generate a maintenance plan that runs this task against all user-created databases. No maintenance tasks are run against the SQL Server system databases.
These databases
Generate a maintenance plan that runs this task against only those databases that are selected. At least one database in the list must be selected if this option is chosen.
Object list
Limit the Selection list to display tables, views, or both. This list is only available if a single database is chosen from the Databases list above.
Selection list
Specify the tables or indexes affected by this task. Not available when Tables and Views is selected in the Object box.
Free space options area
Presents options for applying fill factor to indexes and tables.
Default free space per page
Reorganizes the pages with the default amount of free space. This drops the indexes on the tables in the database, and recreates them with the fill factor that was specified when the indexes were created. This is the default option.
Change free space per page to box
Drop the indexes on the tables in the database and re-create them with a new, automatically calculated fill factor, thereby reserving the specified amount of free space on the index pages. The higher the percentage, the more free space is reserved on the index pages, and the larger the index grows. Valid values are from 0 through 100. Uses the
FILLFACTOR
option.Advanced options area
Presents additional options for sorting indexes and reindexing.
Sort results in tempdb check box
Uses the
SORT_IN_TEMPDB
option, which determines where the intermediate sort results, generated during index creation, are temporarily stored. If a sort operation isn't required, or if the sort can be performed in memory, theSORT_IN_TEMPDB
option is ignored.Pad Index check box
Uses the
PAD_INDEX
option.Keep index online while reindexing check box
Uses the
ONLINE
option, which allows users to access the underlying table or clustered index data and any associated nonclustered indexes during index operations. Selecting this option activates additional options for rebuilding indexes that don't allow for online rebuilds: Do not rebuild indexes and Rebuild indexes offline.Selecting this option also activates Low Priority Used, which uses the
WAIT_AT_LOW_PRIORITY
option. Online index rebuild operations wait for low priority locks forMAX_DURATION
minutes, allowing other operations to proceed while the online index build operation is waiting.Note
Online index operations are not available in every edition of SQL Server. For more information, see Editions and supported features of SQL Server 2022.
MAXDOP check box
Overrides the max degree of parallelism configuration option of
sp_configure
for DBCC CHECKDB. For more information, see DBCC CHECKDB (Transact-SQL)
Define the Update Statistics Task
On the Define Update Statistics Task page, define the database or databases on which table and index statistics are updated. This task uses the
UPDATE STATISTICS
statement. For more information, see UPDATE STATISTICS (Transact-SQL) When finished, select NextThe following options are available on this page.
Databases list
Specify the databases affected by this task.
All databases
Generate a maintenance plan that runs this task against all Microsoft SQL Server databases except
tempdb
.System databases
Generate a maintenance plan that runs this task against SQL Server system databases except
tempdb
and user-created databases.All user databases (excluding
master
,model
,msdb
,tempdb
)Generate a maintenance plan that runs this task against all user-created databases. No maintenance tasks are run against the SQL Server system databases.
These databases
Generate a maintenance plan that runs this task against only those databases that are selected. At least one database in the list must be selected if this option is chosen.
Object list
Limit the Selection list to display tables, views, or both. This list is only available if a single database is chosen from the Databases list above.
Selection list
Specify the tables or indexes affected by this task. Not available when Tables and Views is selected in the Object box.
All existing statistics
Update statistics for both columns and indexes.
Column statistics only
Only update column statistics. Uses the
WITH COLUMNS
option.Index statistics only
Only update index statistics. Uses the
WITH INDEX
option.Scan type
Type of scan used to gather updated statistics.
Full scan
Read all rows in the table or view to gather the statistics.
Sample by
Specify the percentage of the table or indexed view, or the number of rows to sample when collecting statistics for larger tables or views.
Define the History Cleanup Task
On the Define History Cleanup Task page, define the database or databases where you want to discard old task history. This task uses the
EXEC sp_purge_jobhistory
,EXEC sp_maintplan_delete_log
, andEXEC sp_delete_backuphistory
statements to remove history information from themsdb
tables. When finished, select Next.The following options are available on this page.
Select the historical data to delete
Choose the type of task data to delete.
Backup and restore history
Retaining records of when recent backups were created can help SQL Server create a recovery plan when you want to restore a database. The retention period should be at least the frequency of full database backups.
SQL Server Agent Job history
This history can help you troubleshoot failed jobs, or determine why database actions occurred.
Maintenance Plan history
This history can help you troubleshoot failed maintenance plan jobs, or determine why database actions occurred.
Remove historical data older than
Specify age of items that you want to delete. You can specify Hour(s), Day(s), Week(s) (the default), Month(s), or Year(s)
Define the Execute Agent Job Task
- On the Define Execute Agent Job Task page, under Available SQL Server Agent jobs, choose the job or jobs to run. This option isn't available if you have no SQL Agent jobs. This task uses the
EXEC sp_start_job
statement. For more information, see sp_start_job (Transact-SQL). When finished, select Next.
Define Backup Tasks
On the Define Backup Database (Full) Task page, select the database or databases on which to run a full backup. This task uses the
BACKUP DATABASE
statement. For more information, see BACKUP (Transact-SQL). When finished, select Next.The following options are available on this page.
Backup type list
Displays the type of backup to be performed. This is read-only.
Databases list
Specify the databases affected by this task.
All databases
Generate a maintenance plan that runs this task against all Microsoft SQL Server databases except
tempdb
.System databases
Generate a maintenance plan that runs this task against SQL Server system databases except
tempdb
and user-created databases.All user databases (excluding
master
,model
,msdb
,tempdb
)Generate a maintenance plan that runs this task against all user-created databases. No maintenance tasks are run against the SQL Server system databases.
These databases
Generate a maintenance plan that runs this task against only those databases that are selected. At least one database in the list must be selected if this option is chosen.
Backup component
Select Database to back up the entire database. Select File and filegroups to back up only a portion of the database. If selected, provide the file or filegroup name. When multiple databases are selected in the Databases box, only specify Databases for the Backup components. To perform file or filegroup backups, create a task for each database. These options are only available if a single database is chosen from the Databases list above.
Backup set will expire check box
Specifies when the backup set for this backup can be overwritten. Select After and enter a number of days to expiration, or select On and enter a date of expiration. This option is disabled if URL is selected as the backup destination.
Back up to
Specifies the medium on which to back up the database. Select Disk, Tape, or URL. Only tape devices attached to the computer containing the database are available.
Back up database(s) across one or more files
Select Add to open the Select Backup Destination dialog box. This option is disabled if you selected URL as the backup destination.
Select Remove to remove a file from the box.
Select Contents to read the file header and display the current backup contents of the file.
Select Backup Destination dialog box
Select the file, tape drive, or backup device for the backup destination. This option is disabled if you selected URL as the backup destination.
If backup files exist list
Specify how to handle existing backups. Select Append to add the new backups after any existing backups in the file or on the tape. Select Overwrite to remove the old content of a file or tape, and replace it with this new backup.
Create a backup file for every database
Create a backup file in the location specified in the folder box. One file is created for each database selected. This option is disabled if you selected URL as the backup destination.
Create a sub-directory for each database check box
Create a subdirectory under the specified disk directory that contains the database backup for each database being backed up as part of the maintenance plan.
Important
The sub-directory will inherit permissions from the parent directory. Restrict permissions to avoid unauthorized access.
Folder box
Specify the folder to contain the automatically created database files. This option is disabled if you selected URL as the backup destination.
SQL Credential
Select a SQL Credential used to authenticate to Azure Storage. If you don't have an existing SQL Credential you can use, select the Create button to create a new SQL Credential.
Important
The dialog that opens when you select Create requires a management certificate or the publishing profile for the subscription. If you do not have access to the management certificate or publishing profile, you can create a SQL Credential by specifying the storage account name and access key information using Transact-SQL or SQL Server Management Studio. See the sample code in the Create a Credential topic to create a credential using Transact-SQL. Alternatively, using SQL Server Management Studio, from the database engine instance, right-click Security, select New, and select Credential. Specify the storage account name for Identity and the access key in the Password field.
Azure storage container
Specify the name of the Azure storage container
URL prefix
This is automatically generated based on the storage account information stored in the SQL Credential, and Azure storage container name you specified. We recommend that you don't edit the information in this field unless you're using a domain that uses a format other than <storage account>.blob.core.windows.net.
Backup file extension box
Specify the extension to use for the backup files. The default is .bak.
Verify backup integrity check box
Verify that the backup set is complete and that all volumes are readable.
Perform checksum check box
Verify each page for checksum and torn page, if enabled and available, and generate a checksum for the entire backup.
Continue on error check box
Instructs BACKUP to continue despite encountering errors such as invalid checksums or torn pages.
Backup Encryption
To create an encrypted backup, check the Encrypt backup check box. Select an encryption algorithm to use for the encryption step, and provide a Certificate or Asymmetric key from a list of existing certificates or asymmetric keys. The available algorithms for encryption are:
- AES 128
- AES 192
- AES 256
- Triple DES
The encryption option is disabled if you selected to append to existing backup set.
It is recommended practice to back up your certificate or keys and store them in a different location than the backup you encrypted.
Only keys residing in the Extensible Key Management (EKM) are supported.
Block size check box, list
Specifies the physical block size, in bytes. This option typically affects performance when writing to tape devices, RAID arrays, or SAN.
Max transfer size check box, list
Specifies the largest unit of transfer in bytes to be used between SQL Server and the backup media.
Set backup compression list
In SQL Server 2008 (10.0.x) Enterprise (or later versions), select one the following backup compression values:
Value Description Use the default server setting Select to use the server-level default. This default is set by the backup compression default server-configuration option. For information about how to view the current setting of this option, see View or Configure the backup compression default Server Configuration Option. Compress backup Select to compress the backup, regardless of the server-level default.
Important: By default, compression significantly increases CPU usage, and the additional CPU consumed by the compression process might adversely affect concurrent operations. Therefore, you might want to create low-priority compressed backups in a session whose CPU usage is limited by the Resource Governor. For more information, see Use Resource Governor to Limit CPU Usage by Backup Compression (Transact-SQL).Do not compress backup Select to create an uncompressed backup, regardless of the server-level default.
On the Define Backup Database (Differential) Task page, select the database or databases on which to run a partial backup. See the definition list earlier in this article, for more information about the available options on this page. This task uses the
BACKUP DATABASE ... WITH DIFFERENTIAL
statement. For more information, see BACKUP (Transact-SQL). When finished, select Next.On the Define Backup Database (Transaction Log) Task page, select the database or databases on which to run a backup for a transaction log. See the definition list earlier in this article, for more information about the available options on this page. This task uses the
BACKUP LOG
statement. For more information, see BACKUP (Transact-SQL). When finished, select Next.
Define Maintenance Cleanup Tasks
On the Define Maintenance Cleanup Task page, specify the types of files to delete as part of the maintenance plan, including text reports created by maintenance plans and database backup files. This task uses the
EXEC xp_delete_file
statement. When finished, select Next.Important
This task does not automatically delete files in the subfolders of the specified directory. This precaution reduces the possibility of a malicious attack that uses the Maintenance Cleanup task to delete files. If you want to delete files in first-level subfolders, you must select Include first-level subfolders.
The following options are available on this page.
Delete files of the following type
Specify the type of files to be deleted.
Backup files
Delete database backup files.
Maintenance Plan text reports
Delete text reports of previously run maintenance plans.
File location
Specify path to files to be deleted.
Delete specific file
Delete the specific file provided in the File name text box.
Search folder and delete files based on an extension
Delete all files with the specified extension in the specified folder. Use this option to delete multiple files at once, such as all backup files in the Tuesday folder with the .bak extension.
Folder box
Path and name of the folder containing the files to be deleted.
File extension box
Provide the file extension of the files to be deleted. To delete multiple files at one time, like all backup files with the .bak extension in the Tuesday folder, specify .bak.
Include first-level subfolders check box
Delete files with the extension specified for File extension from first-level subfolders under the folder specified in Folder.
Delete files based on the age of the file at task run time check box
Specify the minimum age of the files that you want to delete by providing a number, and unit of time in the Delete files older than the following box.
Delete files older than the following
Specify the minimum age of the files that you want to delete by providing a number, and unit of time (Hour, Day, Week, Month, or Year). Files older than the time frame specified are deleted.
Select Report Options
On the Select Report Options page, select options for saving or distributing a report of the maintenance plan actions. This task uses the
EXEC sp_notify_operator
statement. For more information, see sp_notify_operator (Transact-SQL).When finished, select Next.The following options are available on this page.
Write a report to a text file check box
Save the report in a file.
Folder location box
Specify the location of the file that will contain the report.
E-mail report check box
Send an e-mail when a task fails. To use this task you must have Database Mail enabled and correctly configured with
msdb
as a Mail Host Database, and have a Microsoft SQL Server Agent operator with a valid e-mail address.Agent operator
Specify the recipient of the e-mail.
Mail profile
Specify the profile that defines the sender of the e-mail.
Complete the Wizard
On the Complete the Wizard page, verify the choices made on the previous pages, and select Finish.
On the Maintenance Wizard Progress page, monitor status information about the actions of the Maintenance Plan Wizard. Depending on the options that you selected in the wizard, the progress page might contain one or more actions. The top box displays the overall status of the wizard and the number of status, error, and warning messages that the wizard has received.
The following options are available on the Maintenance Wizard Progress page:
Details
Provides the action, status, and any messages that are returned from action taken by the wizard.
Action
Specifies the type and name of each action.
Status
Indicates whether the wizard action as a whole returned the value of Success or Failure.
Message
Provides any error or warning messages that are returned from the process.
Report
Creates a report that contains the results of the Create Partition Wizard. The options are View Report, Save Report to File, Copy Report to Clipboard, and Send Report as Email.
View Report
Opens the View Report dialog box, which contains a text report of the progress of the Create Partition Wizard.
Save Report to File
Opens the Save Report As dialog box.
Copy Report to Clipboard
Copies the results of the wizard's progress report to the Clipboard.
Send Report as Email
Copies the results of the wizard's progress report into an email message.