yueyue, I have fallen in love with you for

2011-02-09, 01:18:25 PM

SQL数据库的事物

Posted on 2011-08-14 23:16  张超的博客  阅读(266)  评论(0)    收藏  举报

开始事物:begin transaction

提交事物:commit  transaction

回滚事物:rollback transaction

例子:

begin transaction

declare @errorSum int      --定义局部变量

set @errorSum=0  --初始化临时变量

update bank set currentMoney= currentMoney-1000 where customerName='张三'

set @errorSum=@errorSum+@@error    --累计是否有错误

update bank set currentMoney= currentMoney+1000 where customerName='李四'

set @errorSum=@errorSum+@@error    --累计是否有错误

if @errorSum<>0     --如果有错误

    begin

       rollback transaction

    end

else

    begin

        commit  transaction

     end

go

博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3