zoukankan      html  css  js  c++  java
  • sql 事务

     

    use studb
    go
    update bank set currentmoney=currentmoney-1000 where costomername='chen'
    set nocount on
    print '查看转账事务前的行数信息'
    select * from bank

    go
    begin transaction
    declare @errorsum int
    set @errorsum=0update bank set currentmoney=currentmoney-1000
    where customername='zhangsan'
    set @errorsum=@errorsum+@@error
    update bank set currentmoney=currentmoney+100 where customername='lisi'
    set @errorsum=@errorsum+@@error

    print '查看转账事务过程中的余额'
    select * from bank

    if @errorsum<>0
    begin
    print '交易失败。回滚事务'
    rollback transaction
    end
    else
    begin
    print '交易成功,提交成功,写入硬盘,永久保存'
    commit transaction
    end
    go

    print '查看转账事务后的余额'
    select * from bank
    go

  • 相关阅读:
    FileUpload组件
    国际化
    dbutils
    BeanUtils
    c3p0连接池]
    JDBC代码模板
    JDBC基础与连接sql2012
    JSP以及JSP解析原理
    Tomcat使用,部署
    JAVA---反射
  • 原文地址:https://www.cnblogs.com/benzhang/p/1458775.html
Copyright © 2011-2022 走看看