zoukankan      html  css  js  c++  java
  • [大冒险]数据库维护计划和作业删除异常

    http://blog.csdn.net/whbo/archive/2008/04/24/2325099.aspx

    代码
    use [msdb]
    set nocount on
    begin tran
    declare @SubPlanName varchar(200
    --计划名称从Sqlserver 代理->作业查看,
    --
    例如:BakUserDB.子计划,那该值就是“子计划”,赋值给下面的变量
    set @SubPlanName='Subplan_1' --'子计划' 

    --获得外键约束用到的列
    declare @subPlan_id varchar(100),@job_id varchar(100)
        ,
    @msx_job_id varchar(100),@Schedule_id varchar(100)
    select @job_id=job_id,@msx_job_id=msx_job_id,
        
    @subPlan_id=subPlan_id from sysmaintplan_SubPlans where SubPlan_name=@SubPlanName

    --按照顺序删除记录
    if (@SubPlan_id is not null and @SubPlan_id<>''
    delete from sysmaintplan_log where SubPlan_id=@SubPlan_id

    if (@SubPlanName<>'' and @SubPlanName is not null)  
    delete from sysmaintplan_SubPlans where SubPlan_Name=@SubPlanName

    if (@Schedule_id is not null and @Schedule_id <>''
    delete from SysSchedules where Schedule_id=@Schedule_id

    if (@job_id is not null and @job_id<>'')
    delete from sysjobs where job_id=@job_id

    delete
      
    FROM msdb.dbo.sysmaintplan_plans
    --执行上述代码结束后,刷新维护计划的节点,该节点成功删除。
    commit tran
    if @@error<>0 Print '执行失败'
    else Print '执行成功'

    set nocount off
  • 相关阅读:
    Leetcode Unique Binary Search Trees
    Leetcode Decode Ways
    Leetcode Range Sum Query 2D
    Leetcode Range Sum Query
    Leetcode Swap Nodes in Pairs
    Leetcode Rotate Image
    Leetcode Game of Life
    Leetcode Set Matrix Zeroes
    Leetcode Linked List Cycle II
    CF1321A
  • 原文地址:https://www.cnblogs.com/mingle/p/1664613.html
Copyright © 2011-2022 走看看