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

  • 相关阅读:
    触发器
    数据库function和procedure
    java连接数据库
    单例模式
    python入门相关笔记
    ubuntu 系统备份到移动硬盘(tar) 还原到另一台电脑
    大白菜pe 通用pe 安装心得
    18 java 代理模式 (转)
    5 HBase 常用Shell命令
    1、shell 简介
  • 原文地址:https://www.cnblogs.com/ctyy/p/6538091.html
Copyright © 2011-2022 走看看