Sometimes certain SQL Server maintenance plan tasks can be problematic, like Shrink Database, Rebuild Index, Update Statistics, etc. I'd like to search for the use of one or more of these tasks on an instance of SQL server, for further review of whether they are necessary.
Is there a way to query for maintenance plans that perform one or more specific tasks?
(Not limited to the tasks that I mentioned.)
Best Answer
Yes. This can be done by using a combination of the system SSIS tables and XQuery.
Note: In SQL 2012, this will only work for Maintenance Plans created within SSMS. If you used Data Tools to deploy a package that performs maintenance via the project deployment model, this will not work.
XQuery
If you are not familiar with XQuery, you can start here.
Find the task ExecutionType(s) for the Task(s)
The first thing that you'll need to find is the ExecutionType of the task(s) you're looking for.
Query msdb..sysssispackages for the plan name(s).
Example query to retrieve the package XML based on the maintenance plan name:
Click on the results in the PackageDataXml column which will open the raw XML in another query tab.
In the newly opened XML tab, search for the string "ExecutableType". (Nothing fancy required here - just good old-fashioned CTRL+F.)
Search for the maintenance plans using the ExecutableType(s)
The following query uses XQuery and the ExecutableType values that were found in the step above to search in all maintenance plans.