例如:
存储过程中部分语句
insert into   备份表A  select * from [192.168.1.2].test.dbo.原表A
insert into   备份表B  select * from [192.168.1.3].test.dbo.原表B
insert into   备份表C  select * from [192.168.1.4].test.dbo.原表C
现在如果其中一条语句出错是.存储过程失败退出
有没有语句可以让这些语句.其中一条语句出错时,跳过.执行下一条语句

解决方案 »

  1.   


    SET XACT_ABORT OFF
      

  2.   

    多层嵌套..
    Begin TRY
      delete from GrandParent where Name = 'John Smith'
      print 'GrandParent deleted successfully'
    End Try
    Begin Catch
       Print 'Error Deleting GrandParent Record'
       Begin Try
         delete from Parent where GrandParentID = 
         (select distinct ID from GrandParent where Name = 'John Smith')
         Print 'Parent Deleted Successfully'
       End Try
       Begin Catch
         print 'Error Deleting Parent'
         Begin Try
           delete from child where ParentId = 
         (select distinct ID from Parent where GrandParentID = 
         (select distinct ID from GrandParent where Name = 'John Smith'))
           print 'Child Deleted Successfully'
         End Try
         Begin Catch
           Print 'Error Deleting Child'
         End Catch
       End Catch
     End Catch
      

  3.   

    SQL  2000 不能执行 Try