码迷,mamicode.com
首页 > 数据库 > 详细

数据库的回滚

时间:2016-01-26 18:03:31      阅读:165      评论:0      收藏:0      [点我收藏+]

标签:

 1   begin try    
 2   begin transaction --开始事务     
 3   begin
 4     insert into Table_A (columnabc values (1,2)
 5   end
 6   commit transaction --提交事务
 7   end try 
 8   begin catch --获取错误
 9     --select ERROR_NUMBER() as errornumber --错误原因
10     --SELECT ERROR_NUMBER() AS 错误号,  
11     --ERROR_SEVERITY() AS 错误等级,  
12     --ERROR_STATE() as 错误状态,  
13     --DB_ID() as 数据库ID,  
14     --DB_NAME() as 数据库名称,  
15     --ERROR_MESSAGE() as 错误信息;
16     --rollback transaction 
17   end catch
 1     --transaction demo
 2     create procedure  [dbo].[xxx] as
 3     begin transaction
 4     declare @error int 
 5         select @error =0
 6         --insert into xxx...
 7         select @error = @error+@@ERROR
 8         --update xxx set xxx...
 9         select @error = @error+@@ERROR
10         --delete from xxx...
11         select @error = @error+@@ERROR
12     if @@ERROR=0
13     commit transaction
14     else 
15     rollback transaction

 

数据库的回滚

标签:

原文地址:http://www.cnblogs.com/qingyanxiaochen/p/5160983.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!