首页 > 数据库技术 > 详细

SQL Server 简单事务学习

时间:2014-10-30 22:21:23      阅读:307      评论:0      收藏:0      [点我收藏+]
select * from bank
insert into bank values(10000)
insert into bank values(20000)

--打开一个事务
begin tran
--定义临时变量
declare @num int = 0;
update bank set balance=balance-15000 where Id=1
set @num = @num + @@error; --上一条语句出错次数
update bank set balance=balance+15000 where Id=2
set @num = @num + @@error;
if @num <> 0 begin
--回滚事务
rollback tran
end
else  begin
--提交事务
commit tran
end

 

SQL Server 简单事务学习

原文:http://www.cnblogs.com/han1982/p/4063734.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!