Skip to content

Instantly share code, notes, and snippets.

@whereisaaron
Created November 12, 2022 11:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save whereisaaron/50b928719abf5d02df7c80b95e2d9deb to your computer and use it in GitHub Desktop.
Save whereisaaron/50b928719abf5d02df7c80b95e2d9deb to your computer and use it in GitHub Desktop.
Clean up orphaned SQL Server Maintenance Plan subplans and their logs, use this if you get a conflict error deleting a job
--
-- Clean up orphaned Maintenance Plan subplans and their logs
-- Use this if you get a conflict error deleting a job
--
use [msdb]
GO
delete from msdb..sysmaintplan_log
where plan_id not in (
select plan_id from msdb..sysmaintplan_plans);
GO
delete from msdb..sysmaintplan_subplans
where plan_id not in (
select plan_id from msdb..sysmaintplan_plans);
GO
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment