Created
November 12, 2022 11:27
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- | |
-- 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