SQLServer存储过程中事务的创建

直接上代码

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'

你可能感兴趣的:(#,数据库)