数据库实验报告7.pdfVIP

  • 10
  • 0
  • 约4.66千字
  • 约 7页
  • 2021-01-07 发布于江苏
  • 举报
《数据库原理》实验报告 题目:实验七 学号 姓名 班级 日期 事务与并发控 Xxxx Xx Xxx 2016.11.10 一. 实验内容、步骤以及结果 假设学校允许学生将银行卡和校园卡进行绑定, 在 student 数据库中有如下的基本 表, 其中校园卡编号 cardid 即为学生的学号: icbc_card(studcardid,icbcid,balance) //校园卡 ID,工行卡 ID,银行卡余额 campus_card(studcardid,balance) //校园卡 ID,校园卡余额 数据创建的代码: 1. 编写一个事务处理 (begin tran)实现如下的操作:某学号为的学生要从 银行卡中转账 200 元到校园卡中,若中间出现故障则进行 rollback。(15 分) 修改后的结果: 2. 针对本题的数据库和表,分别用具体的例子展现四种数据不一致问题:丢失修改、 读脏数据、不可重复读和幻读 (删除和插入)。(40 分,每种数据不一致 10 分) 丢失修改: --事务一: begin tran declare @balance decimal(10,2) select @balance=balance from campus_card where studcardid waitfor delay00:00:05 set @balance=@balance-10 update campus_card set balance=@balance where studcardid commit tran go select balance from campus_card where studcardid --事务二: begin tran declare @balance1 decimal(10,2) select @balance1=balance from campus_card where studcardid set @balance1=@balance1-20 update campus_card set balance=@balance1 where studcardid commit tran go select balance from campus_card where studcardid 【事务 1】更改了数据,结果为 60,但是没有被读到。最终【事务 2】的结果 50 覆 盖了【事 务 1】的更改值,结果不是期望值 40 读脏数据 --事务一: begin tran declare @balance decimal(10,2) select @balance=balance from campus_card where studcardid update campus_card set balance=@balance+100 where studcardid waitfor delay00:00:05 rollback tran--回滚 go select balance from campus_card where studcardid --事务二: begin tran declare @balance decimal(10,2) select @balance=balance from campus_card where studcardid update campus_card se

文档评论(0)

1亿VIP精品文档

相关文档