关于事务

gutlgutl 2007-02-05 03:01:25
creat proc name
as

insert table1 select tb from ..
insert table2 select tb from...
.....
.....
我想加个事务,如果这个过程中出现错误,我想让之前插入的数据全部回滚,应该怎么写,是直接在这里写,还是建个触发器比较好?
...全文
218 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
sky266 2007-02-05
  • 打赏
  • 举报
回复
creat proc name
as
begin tran
insert table1 select tb from ..
insert table2 select tb from...
if @@error>0
begin
rollback tran
end
else
begin
commit tran
end
zlp321002 2007-02-05
  • 打赏
  • 举报
回复
creat proc name
as
set xact_abort on
begin
begin tran
insert table1 select tb from ..
insert table2 select tb from...
.....
.....
commit tran
end

34,588

社区成员

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

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