Mssql 异常捕捉

hq0927 2008-07-03 09:25:05
例如:
存储过程中部分语句
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


现在如果其中一条语句出错是.存储过程失败退出


有没有语句可以让这些语句.其中一条语句出错时,跳过.执行下一条语句
...全文
171 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
hq0927 2008-07-03
  • 打赏
  • 举报
回复
SQL 2000

不能执行 Try
pt1314917 2008-07-03
  • 打赏
  • 举报
回复
goto
hery2002 2008-07-03
  • 打赏
  • 举报
回复
多层嵌套..
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
hery2002 2008-07-03
  • 打赏
  • 举报
回复
2005--
TRY...CATCH..
nzperfect 2008-07-03
  • 打赏
  • 举报
回复
[Quote=引用楼主 hq0927 的帖子:]
例如:
存储过程中部分语句
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


现在如果其中一条语句出错是.存储过程失败退出


有没有语句可以让这些语句.其中一条语句出错时,跳过.执行下一条语句
[/Quote]

本来就是这样的。
懒牛科技 2008-07-03
  • 打赏
  • 举报
回复
加个事务!
nzperfect 2008-07-03
  • 打赏
  • 举报
回复
有才
zhou968 2008-07-03
  • 打赏
  • 举报
回复

SET XACT_ABORT OFF

34,874

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server相关内容讨论专区
社区管理员
  • 基础类社区
  • 二月十六
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧