-1

This question already has an answer here:

How to create maintenance plan using sql script with out maintenance plan wizard. Please don't suggest olahallengren solution. His script is not exact relpica of maintenance plan.This means, he created only jobs but not maintenanceplan name in management-->maintenaceplan fodler.So, let me know, Is it possible or not to create maintenance plan using sql script?

marked as duplicate by Colin 't Hart, hot2use, Erik Darling, Tom V, Paul White sql-server Sep 4 '18 at 11:33

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

3

The answer by Riccardo Bassilichi on Copy maintenance plans to a different server might offer a solution.

You could insert it in your own table and create and specify your own name like the following (original by Riccardo Bassilichi, changed a little by me):

INSERT INTO msdb.dbo.sysssispackages
SELECT        
'CustomName' as name,  --name of copied maintenance plan
 newid() as id ,  --new id for the maint plan
description, 
createdate, 
folderid, 
ownersid, 
cast(
    cast(

            cast(
                CAST(packagedata AS VARBINARY(MAX)) AS varchar(max)
            )
    as XML) 
as VARBINARY(MAX)) as packagedata, 
packageformat, 
packagetype, 
vermajor, 
verminor, 
verbuild, 
vercomments, 
verid, 
isencrypted, 
readrolesid, 
writerolesid

FROM
msdb.dbo.sysssispackages AS sysssispackages_1
WHERE        
(name = 'YourMaintenancePlanName')

Change the old and new maintenance plan names to your maintenance plan and the desired name of the new maintenance plan.

Don't forget to delete the schedule of the newly created maintenance plan, schedule it again, and save.

Not the answer you're looking for? Browse other questions tagged or ask your own question.