+ -
当前位置:首页 → 问答吧 → sql2000 事务问题

sql2000 事务问题

时间:2011-12-05

来源:互联网

代码如下:其中三条语句,中间那条语句是会出错,我的想法是,如果任何一条语句出错,都回滚,但像现在这样写法,即使中间条语句出错,第一条和第三条还是照样运行,请教该如何写?
SQL code
begin tran
 delete from temp_001 where id>37000
 insert into temp_001 select null,0,0,0,0,0,0,0,0,0,0,0
 delete from temp_002 where id>37000

if @@error<>0 --判断如果三条语句有任何一条出现错误

begin
     rollback tran --–开始执行事务的回滚,
end else   --如何三条都执行成功
begin 
    commit tran --执行这个事务的操作
end



作者: twinpat   发布时间: 2011-12-05

任何一条语句出错,就全部回滚,当成都没有操作过一样

作者: twinpat   发布时间: 2011-12-05

不会吧!

作者: qianjin036a   发布时间: 2011-12-05

SQL code

begin tran
    delete from temp_001 where id>37000
    insert into temp_001 select null,0,0,0,0,0,0,0,0,0,0,0
    delete from temp_002 where id>37000
commit tran --执行这个事务的操作

if @@error<>0 --判断如果三条语句有任何一条出现错误     
    rollback tran --–开始执行事务的回滚,

作者: geniuswjt   发布时间: 2011-12-05

SQL code
begin try
    begin tran
     delete from temp_001 where id>37000
     insert into temp_001 select null,0,0,0,0,0,0,0,0,0,0,0
     delete from temp_002 where id>37000
     commit tran
end try
begin catch
     rollback tran 
end  catch   


作者: ssp2009   发布时间: 2011-12-05

热门下载

更多