题目详情

某超市销售系统的部分关系模式如下:商品表: Commodity(Ccode, Cname, price,qty),其中属性含义分别为:商品编号、商品名称、价格、库存量,有专门的事务保证库存量足够大,销售时无需检测。销售表: Sale(Sno,Ccode, amount, Stime),其中属性含义分别为:销售编号,商品编号、数量、时间。其销售业务规则如下:顾客在超市挑选好商品后,带商品到结算处结算付款,结算处有多名结算员使用多台机器进行结算。结算员负责扫顾客购买商品的条码和数量,由系统后台结算程序计算出顾客购买商品的总金额,修改商品表的商品库存量,并将销售信息写入销售表。

【问题1】假设有两个顾客同时购买同一条码的商品,结算事务修改该商品的库存量(记为数据项 X),部分的调度如图 5-1 所示。

中级数据库系统工程师,章节练习,基础复习,事务管理

如果购买前 X 的初值为 10,则上述调度执行完成后,X 的值是多少?属于哪一类不一致性?

【问题2】 引入独占锁指令 Xlock()和解锁指令 Unlock(),对【问题 1】中的调度进行重写,要求满足两段锁协议,且事务 T1、T2 首条指令的相对请求时间与【问题 1】中的相同。

【问题 3】下面是用 SQL 实现的结算程序,请补全空缺处的代码。要求在保证销售信息不丢失的前提下,达到最大的系统并发度。CREATE PROCEDURE buy(IN: CommNo VARCHAR(20), IN: AmountBuy INT)BEGIN//输入合法性验证if(: AmountBuyimage.png1) return-1;SET TRANSACTION ISOLATIONLEVEL (a);BEGIN TRANSACTION;//插入销售记录INSERT INTO SaleVALUES(getGUID(),: CommNo, AmountBuy, getDATETIME());//函数 getGUID():获取唯一值//函数 getDATETIME():获取当前系统日期时间If error ∥error 是由 DBMS 提供的上一句 SQL 的执行状态BEGNROLLBACK; return-2;END//修改库存数量UPDATE CommoditySETqty= (b)WHERE Ccode=: CommNo;if errorBEGINROLBACK; return-3;END(c)END

正确答案及解析

正确答案
解析

【问题1】(1)第2人,并发操作出现了丢失更新的问题,第2个的更新覆盖了第1个的更新,原因是破坏了事物的隔离性。(2)会产生死锁,由于数据X同时被1和2加锁了S锁,再对方没有释放的时候,都无法加成功X锁,导致1和2一直都处于等待的状态(3)XLock(X) a=R(X) W(b,X)UNLock(X)

【问题2】中级数据库系统工程师,章节练习,基础复习,事务管理

【问题3】(a)REPEATABLE READ(b)qty-:AmountBuy;(c)Commit;Return 0;END TRANSACTION

你可能感兴趣的试题

单选题

Advancements in ( )have contributed to the growth of the automotive industry through the creation and evolution of self-driving vehicles.

  • A.Artificial Intelligence
  • B.Cloud Computing
  • C.Internet of Things
  • D.Big Data
查看答案
单选题

In project human resource management , ( )is not a source of power for the project manager.

  • A.referent power
  • B.expert power
  • C.reward power
  • D.audit power
查看答案
单选题

At the project establishment stage , the feasibility study mainly includes techinical feasibility analysis , ( ), operation environment feasibility analysis and other aspects of feasibility analysis.

  • A.detail feasibility analysis
  • B.opportunity analysis
  • C.economic feasibility analysis
  • D.risk analysis
查看答案
单选题

( )is a grid that shows the project resources assigned to each work package.

  • A.Stakeholder engagement assessment matrix
  • B.Requirements traceability matrix
  • C.Probability and impact matrix
  • D.Responsibility assignment matrix
查看答案
单选题

Xinhua News Agency reported in January 2022,Chian will further promote the developmet of a digital economy during the 14th Five-Year Plan eriod(2021-2025). The plan also emphasized industrial ( )transformation.

  • A.digital
  • B.networking
  • C.intelligentize
  • D.informatization
查看答案

相关题库更多 +