zoukankan      html  css  js  c++  java
  • 数据库的回滚

     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

     切记,truncate语句不会回滚。

  • 相关阅读:
    委托系列整理
    EF Lambda 多表查询
    枚举,Enum,常规使用demo记录
    自定义Window 服务
    xpath 操作XML
    MVC 自定义过滤器
    时间比对,常用细节记录
    Lock锁_线程_线程域
    break、continue和goto 三者作用介绍
    .net 学习路线感想
  • 原文地址:https://www.cnblogs.com/qingyanxiaochen/p/5160983.html
Copyright © 2011-2022 走看看