分享你我的心得.
共乘一片美好网络.

解决 SQLSERVER 无法删除作业

USE [msdb]
DECLARE @job_name VARCHAR(100)
SET @job_name =’作业名称’

–注:jobName为维护计划对应的jobName
–删除在计划里面的日志
DELETE
sysmaintplan_log
FROM
sysmaintplan_subplans AS subplans
INNER JOIN sysjobs_view AS syjobs ON subplans.job_id = syjobs.job_id
INNER JOIN sysmaintplan_log ON subplans.subplan_id =sysmaintplan_log.subplan_id
WHERE
(syjobs.name = @job_name)

–删除代理的作业
DELETE
sysjobschedules FROM sysjobs_view v
INNER JOIN sysjobschedules o ON v.job_id=o.job_id
WHERE
v.name=@job_name

–删除子计划
DELETE
sysmaintplan_subplans
FROM
sysmaintplan_subplans AS subplans
INNER JOIN sysjobs_view AS syjobs ON subplans.job_id = syjobs.job_id
WHERE
(syjobs.name = @job_name)

–删除作业
DELETE FROM msdb.dbo.sysjobs_view WHERE name = @job_name

赞(0)
未经允许不得转载:小叶白龙博客 » 解决 SQLSERVER 无法删除作业
分享到: 更多 (0)

评论 抢沙发

评论前必须登录!