Posted on 2016-01-09 19:24
魔のkyo 阅读(384)
评论(0) 编辑 收藏 引用 所属分类:
SQL
use [msdb]
declare @job_name varchar(100)
set @job_name = N'jobName'
--注: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
转自:http://www.cnblogs.com/EleMMent/p/3625455.html