SQL Server: Maintenance Plan Execution Program

Is there a way to programmatically execute (run) a SQL Server maintenance plan? We have a Windows service that runs at night and updates the database with a lot of data. Upon completion, we would like to run a maintenance plan in the database for launch.

+7
source share
2 answers

You can get started, which is part of your sp_start_job maintenance plan :

use msdb; go exec dbo.sp_start_job N'job_name' ; go 
+8
source

If you get the error message β€œCould not find the stored procedure dbo.sp_start_job”. try the following:

 execute msdb.dbo.sp_maintplan_start @plan_id = N'549EDF1B-5712-472E-9722-DD81F622A3C2' 

You will receive guidance on this request:

 SELECT s.id AS [ID] FROM msdb.dbo.sysmaintplan_plans AS s WHERE s.name=N'MyMaintenancePlan' 
+5
source

All Articles