Microsoft Docs – SQL Server Maintenance Plans

What are Maintenance Plans?

Maintenance Plans provide a graphical interface for creating and managing common SQL Server maintenance tasks such as Backup, Rebuild Index, and Update Statistics. They simplify routine administrative activities by allowing DBAs to schedule, configure, and automate these tasks within SQL Server Management Studio (SSMS).

Key Features

Typical Maintenance Plan Workflow

Maintenance Plan workflow diagram

1. **Create a new plan** – Use the Maintenance Plan Wizard or Designer.
2. **Add tasks** – Choose from backup, index rebuild, check DB integrity, etc.
3. **Configure task properties** – Set destination, schedule, and options.
4. **Set a schedule** – Attach the plan to a SQL Server Agent job.
5. **Run & monitor** – Review logs and history for each execution.

Sample Maintenance Plan Script

USE [msdb];
GO
DECLARE @plan_id UNIQUEIDENTIFIER;

-- Create a new maintenance plan
EXEC dbo.sp_add_maintenance_plan
    @plan_name = N'Nightly Maintenance',
    @description = N'Daily backup, index rebuild, and statistics update',
    @plan_id = @plan_id OUTPUT;
GO

-- Add a backup task
EXEC dbo.sp_add_maintplan_subplan
    @plan_id = @plan_id,
    @subplan_name = N'Daily Backup',
    @subplan_id = @subplan_id OUTPUT;
GO

-- Additional tasks can be added using sp_add_maintplan_task

References