zoukankan      html  css  js  c++  java
  • 用新学的知识 写了一段小代码

    use myschool
    go
    if exists(select*from sysobjects where name='bank')
    drop table bank
    go
    create table bank
    (
    customername char(10),
    currentmoney money
    )
    go
    alter table bank
    add constraint ck_currentmoney check(currentmoney>=0)
    go
    insert into bank(customername,currentmoney) values('张三',1000)
    insert into bank(customername,currentmoney) values('李四',12)
    insert into bank(customername,currentmoney) values('王二麻子',3)
    go

    --select*from bank


    -- update bank set currentmoney=currentmoney-10000
    -- where customername='王二麻子'
    -- update bank set currentmoney=currentmoney+10000
    --where customername='李四'
    -- go






    use myschool
    go
    print'查看转账之前余额'
    select *from bank
    go
    begin transaction
    declare @errorsum int

    set @errorsum=0
    update bank set currentmoney=currentmoney-3
    where customername='王二麻子'
    set @errorsum=@errorsum+@@ERROR
    update bank set currentmoney=currentmoney+3
    where customername='李四'
    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

  • 相关阅读:
    Android获取当前时间的3中方法总结
    解决 C# .NET WebClient WebRequest请求缓慢的问题
    无刷新的批量图片上传插件.NET版
    <img>标签显示本地路径的图片的.NET解决方案
    无刷新分页
    Shader基本类型
    shader内置变量和函数
    Shader基础
    Lua中的基本函数库
    Lua中的操作系统库
  • 原文地址:https://www.cnblogs.com/ctyy/p/6538091.html
Copyright © 2011-2022 走看看