create procedure T_UserDealDetails_Insert@UserID int,@DealTime datetime,@DetailMoney money,@FormalitiesFees money,@SchemeNumber nvarchar(50),@RelatedUserID int,@PayNumber nvarchar(50),@PayBank nvarchar(50),@Memo nvarchar(50),@OperatorUserID int,@AlipayID nvarchar(50),@AlipayName nvarchar(50),@TenpayID nvarchar(50),@TenpayName nvarchar(50)
AS
insert into [T_UserDealDetails]([UserID],[DealTime],[DealType],[DetailMoney],[FormalitiesFees],[SchemeNumber],[RelatedUserID],[PayNumber],[PayBank],[Memo],[OperatorUserID],[AlipayID],[AlipayName],[TenpayID],[TenpayName])VALUES(@UserID,@DealTime,1,@DetailMoney,@FormalitiesFees,@SchemeNumber,@RelatedUserID,@PayNumber,@PayBank,@Memo,@OperatorUserID,@AlipayID,@AlipayName,@TenpayID,@TenpayName)update T_Users set Balance=@DetailMoney where T_Users.UserID=@UserID
这个写事务回滚怎么写啊/?
我还没用过事务回滚。听老师提过一次。然后也没写过代码。。现在要写了。呃。不会呃。请教下大家。教一把吧。谢了喔。
在存储过程后面加上:
if @@error<>0
rollback tran
else
commit tran
--打开自动回滚,出错时会自动回滚当前事务
set xact_abort on
--开始事务
begin tran
insert into [T_UserDealDetails]([UserID],[DealTime],[DealType],[DetailMoney],[FormalitiesFees],[SchemeNumber],[RelatedUserID],[PayNumber],[PayBank],[Memo],[OperatorUserID],[AlipayID],[AlipayName],[TenpayID],[TenpayName])VALUES(@UserID,@DealTime,1,@DetailMoney,@FormalitiesFees,@SchemeNumber,@RelatedUserID,@PayNumber,@PayBank,@Memo,@OperatorUserID,@AlipayID,@AlipayName,@TenpayID,@TenpayName)update T_Users set Balance=@DetailMoney where T_Users.UserID=@UserID
--提交事务
commit tran