Home » Default » Sqlserver删除作业

删除作业
use [msdb]
declare @job_name varchar(100)
set @job_name = N'正式库每天凌晨3:00第二次完整备份.Subplan_1'
--注:job_name为维护计划对应的job name
--删除在计划里面的日志
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
--查询有哪些作业
select * from msdb.dbo.sysjobs_view

标签: SqlServer 查看作业 删除作业

添加新评论

V