直接上代码
if (exists(select * from sys.objects where name='JayJayToTest')) drop proc JayJayToTest go create proc JayJayToTest @GiveMoney int, @UserName nvarchar(20) as beginset nocount on; begin tran; begin try update BankTest set Money = Money-@GiveMoney where Name=@UserName; update BankTest set Money = Money+@GiveMoney where Name='test'; commit; end try begin catch rollback tran; print ('发生异常,事务进行回滚'); end catch end go exec JayJayToTest 10,'jayjay'