怎么用事务,怎么回滚

aierong 2003-09-04 11:22:18
create proc proc_my
as
create table a(
i tinyint,
ii smallint,
iii int
)
insert into a values(1,11,111)
insert into a values(2,11,111)
insert into a values(3,11,111)
insert into a values(4,18,111)
insert into a values(7,81,111)

怎么判断过程里面的操作全部成功,要是不成功,怎么样回滚,是不是要用事务
请大家帮忙我改这个过程
...全文
77 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
aierong 2003-09-04
  • 打赏
  • 举报
回复
create proc proc_my
as
begin transaction
create table a(
i tinyint,
ii smallint,
iii int
)
if @@error<>0
rollback
insert into a values(1,11,111)
if @@error<>0
rollback
insert into a values(2,11,111)
if @@error<>0
rollback
insert into a values(3,11,111)
if @@error<>0
rollback
insert into a values(4,18,111)
if @@error<>0
rollback
insert into a values(7,81,111)
if @@error<>0
rollback
commit transaction




这样对吗
sysweb 2003-09-04
  • 打赏
  • 举报
回复
conntemp.BeginTrans
中间放程序
conntemp.CommitTrans
aierong 2003-09-04
  • 打赏
  • 举报
回复
ding
yelook 2003-09-04
  • 打赏
  • 举报
回复
begin transaction a
SET NOCOUNT ON
SET XACT_ABORT ON
create table a(
i tinyint,
ii smallint,
iii int
)
insert into a values(1,11,111)
insert into a values(2,11,111)
insert into a values(3,11,111)
insert into a values(4,18,111)
insert into a values(7,81,111)
commit transaction
txlicenhe 2003-09-04
  • 打赏
  • 举报
回复
begin tran
insert into a values(1,11,111)
if @@error <> 0 then goto Err
insert into a values(2,11,111)
if @@error <> 0 then goto Err
insert into a values(3,11,111)
if @@error <> 0 then goto Err
insert into a values(4,18,111)
if @@error <> 0 then goto Err
insert into a values(7,81,111)
if @@error <> 0 then goto Err
commit
return
Err:
rollback
pengdali 2003-09-04
  • 打赏
  • 举报
回复
begin tran
insert into a values(1,11,111)
insert into a values(2,11,111)
insert into a values(3,11,111)
insert into a values(4,18,111)
insert into a values(7,81,111)
commit tran
pengdali 2003-09-04
  • 打赏
  • 举报
回复
begin tran
insert into a values(1,11,111)
insert into a values(2,11,111)
insert into a values(3,11,111)
insert into a values(4,18,111)
insert into a values(7,81,111)
commit tran
aierong 2003-09-04
  • 打赏
  • 举报
回复

34,874

社区成员

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

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