set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
goALTER procedure [dbo].[proc_Approve]
@uid int,
@money float,
@appid int,
@remitHistoryId int
as
update RemitHistory set ApproveState=@appid where RemitHistoryId=@remitHistoryId
update UserInfo set UMoney=@money where UID=@uid
go

解决方案 »

  1.   

    as 
    begin
      update RemitHistory set ApproveState=@appid where RemitHistoryId=@remitHistoryId 
      update UserInfo set UMoney=@money where UID=@uid 
    end
    go 
      

  2.   

    procedure 'uid ','money ','appid ','remitHistoryId '
      

  3.   

    ALTER procedure [dbo].[proc_Approve] 
    @uid int, 
    @money float, 
    @appid int, 
    @remitHistoryId int 
    as 
    declare @err int 
    set @err=0
    begin tran
    update RemitHistory set ApproveState=@appid where RemitHistoryId=@remitHistoryId 
    set @err=@err+abs(@@error)
    update UserInfo set UMoney=@money where UID=@uid 
    set @err=@err+abs(@@error)
    if @err <>0
       rollback
    else
      commit
    go 
      

  4.   

    执行2跳sql语句以上的都要用到事物啊,楼上的高手高见啊.
      

  5.   

    其實不一定要事務,兩條寫在一起就好了,用事務是當兩條UPDATE都成功才提交,否則一條出現錯誤,就全回滾
    保持數據一致性
      

  6.   

    对,我之前用我的那个写法,一条sql语句他也执行,而另一条sql语句没有执行。
    所有上csdn来问问的,果然还是要用事物的。