SQLSERVER 2014 删除数据库定时备份任务提示失败DELETE 语句与 REFERENCE 约束“FK_subplan_job_id“冲突 ,错误如图:
问题原因:不能直接删除作业 任务,需要先删除计划里面的日志、删除代理作业、删除子计划以后才能删除作业。
解决方案如下:
--注:jobsname为维护计划对应的job nameset @jobsname = N'完整备份.Subplan_1'--删除在计划里面的日志
delete sysmaintplan_log from sysmaintplan_subplans as subplansinner join sysjobs_view as syjobs on subplans.job_id = syjobs.job_idinner join sysmaintplan_log on subplans.subplan_id =sysmaintplan_log.subplan_id
where syjobs.name = @jobsname--删除代理的作业
delete sysjobschedules from sysjobs_view v
inner join sysjobschedules o on v.job_id=o.job_id where v.name=@jobsname--删除子计划
delete sysmaintplan_subplans from sysmaintplan_subplans as subplans
inner join sysjobs_view as syjobs on subplans.job_id = syjobs.job_id
where (syjobs.name = @jobsname)--删除作业
delete from msdb.dbo.sysjobs_view where name =@jobsname