首页 > 代码库 > SQL Server 简单事务学习

SQL Server 简单事务学习

select * from bankinsert into bank values(10000)insert into bank values(20000)--打开一个事务begin tran--定义临时变量declare @num int = 0;update bank set balance=balance-15000 where Id=1set @num = @num + @@error; --上一条语句出错次数update bank set balance=balance+15000 where Id=2set @num = @num + @@error;if @num <> 0 begin--回滚事务rollback tranendelse  begin--提交事务commit tranend

 

SQL Server 简单事务学习