http://expert.csdn.net/Expert/topic/1694/1694447.xml?temp=.2850916

解决方案 »

  1.   

    你应该将第一个“事务”先写入临时表。但是我还是觉得只有用 3GL 思想来看流程的人,非常容易人为将程序流程变得很繁琐和别扭。不要多重循环,不要针对单条记录操作。因该整个流程简练地用几个顺序摆放的SQL语句解决问题。
      

  2.   

    to:w_rose(w_rose) 
    不知道3GL思想是什么思想
    我写了一个存储过程流程如下:
    create proc myproc as
    begin tran a
    update table set f1=1,f2=3
    exec other_proc1 p1,p2 out //调用别外一存储过程,根据p2返回值决定继续还是回滚
    if(p2 <>1)
    begin
       select message='error'
       rollback tran a
    end
    insert into table2 (...)values(....)
    if(@@rowcount <>1)
    begin
       select message='error'
       rollback tran a
    end
    exec other_proc2 p1,p3 out //调用别外一存储过程,根据p2返回值决定继续还是回滚
    if(p3 <>1)
    begin
       select message='error'
       rollback tran a             //我的问题就是如果在这回滚的话是否对other_proc1内部
                                   //事务进行回滚?
    end
    delete table where ....
    if(@@rowcount=1)
    begin
       commit tran a
       select message='ok'
       return
    end
    else
    begin
       rollback tran a
       select message='error'
       return
    end