数据库第八章答案
数据库原理及应用第八章课后习题答案
习题81、什么是数据库的安全性?数据库的安全性是指数据库的任何数据都不允许受到恶意的侵害或未经授权的存取或修改。
主要内涵包括三个方面:①保密性:不允许未经授权的用户存取数据。
②完整性:只允许被授权的用户修改数据。
③可用性:不应拒绝已授权的用户对数据进行存取。
2、什么是数据库的完整性?数据库的完整性是指数据库中数据的正确性和一致性。
数据库的完整性对数据库应用系统非常重要。
3、什么是数据库的完整性约束条件?为了保证数据库中的数据完整性,SQL Server设计了很多数据完整性约束:实体完整性、域完整性、参照完整性、用户定义完整性。
4、DBMS的完整性控制机制应具有哪些功能?1)数据库的完整性约束能够防止合法用户向数据库中添加不合语义的数据。
2)完整性控制机制易于理解,可以降低应用程序的复杂性,提高运行效率。
3)合理的数据完整性设计,能够兼顾数据库的完整性和系统的性能。
完善的数据库完整性,有助于尽早发现应用程序的错误。
5、DBMS在实现参照完整性时需要考虑哪些方面?强制参照完整性时,SQL Server将防止用户执行下列操作:1)在主表中没有关联的记录时,将记录添加或更改到相关表中。
2)更改主表中的值,导致相关表中生成孤立记录。
3)从主表中删除记录,但仍存在于该记录匹配的相关记录。
6、在关系系统中,当操作违反实体完整性、参照完整性和用户定义完整性约束条件时,一般是如何处理的?系统可以采用以下的策略加以处理:1)拒绝(NO ACTION)执行:不允许该操作执行,该策略一般为默认策略。
2)级联(CASCADE)操作:当删除或修改被参照表的一个元组造成了与参照表不一致,则删除或修改参照表中的所有造成不一致的元组。
3)设置为空值(SET-NULL):当删除或修改被参照表的一个元组造成了与参照表不一致,则将参照表中的所有造成不一致的元组的对应属性设置为空值。
7、数据库安全性和计算机系统的安全性有什么关系?计算机系统中,安全措施是一级一级层层设置。
数据库系统基础教程第八章答案
50 2 50 4 4+ 46p1 2p2 + 4ห้องสมุดไป่ตู้p3
50 1 26 4 4 + 46p1 - 3p2 + 22p3
2 2 50 6 6 - 4p1 - 4p2 + 44p3
2 1 26 6 6 - 4p1 5p2 + 20p3
50 2 26 6 6 - 44p1 4p2 + 20p3
2 2 26 8 8 - 6p1 6p2 + 18p3
Insertions into PC: INSERT INTO NewPC SELECT maker, ‘ newModel’ , ‘ newSpeed ’ , ‘ newRam ’ , ‘ newHd ’ , ‘ newPrice FROM Product WHERE model = ‘ newModel’; Deletions from Product with type equal to ‘ pc ’: DELETE FROM NewPC WHERE maker = ‘ deletedMaker ’ AND model= ’ deletedModel ’;
‘ f ’;
b) SELECT from RichExec, StudioPres where = ; c) SELECT from ExecutiveStar, StudioPres WHERE Worth >= 50000000 AND StudioPres.cert# = RichExec.cert#; Section 2 Exercise 8.2.1 The views RichExec and StudioPres are updatable; however, the StudioPres view needs to be created with a subquery. CREATE VIEW StudioPres (name, address, cert#) AS SELECT , MovieExec.address, MovieExec.cert# FROM MovieExec WHERE MovieExec.cert# IN (SELECT presCt# from Studio); Exercise 8.2.2 a) Yes, the view is updatable. b)
数据库第8章习题参考答案
第8章习题参考答案2.求程序的运行结果(1)Public Sub 习题8_2_1()Dim i As IntegerDebug.Print Tab(10); "*"For i = 1 To 5Debug.Print Tab(10 - i); "*"; Spc(i - 1); "*"; Spc(i - 1); "*"Next iFor i = 4 To 1 Step -1Debug.Print Tab(10 - i); "*"; Spc(i - 1); "*"; Spc(i - 1); "*"Next iDebug.Print Tab(10); "*"End Subrun:***** * ** * ** * ** * ** * ** * ** * *****(2)Public Sub 习题4_2_2()Dim x, y, i As Doublex = 0: y = 0For i = 1 To 8If i Mod 2 <> 0 Thenx = x - iElsey = y + iEnd IfNextDebug.Print "i="; iDebug.Print "x="; xDebug.Print "y="; yEnd Subrun:x=-16y= 20(3)Public Sub习题4_2_3()Dim m, s, k As Doublem = 28s = 0k = 1Do While k <= Int(m / 2)If Int(m / k) = m / k ThenDebug.Print ks = s + kEnd Ifk = k + 1LoopDebug.Print "s="; sEnd Subrun:124714s= 28(4)Public Sub 习题8_2_4()Dim n, a1, a2, a3, i As Doublen = Val(InputBox("请输入n,要求n>=3"))If n <= 2 ThenExit SubEnd Ifa1 = 1a2 = 1Debug.Print a1; a2For i = 2 To n - 1a3 = a1 + a2a1 = a2a2 = a3Debug.Print a3NextEnd Sub1 12353.改错题(1)Public Sub 改错8_3_1()Dim i, n, s As Doublen = Val(InputBox("请输入n"))i = 2: s = 1Do While i <= ns = s + ii = i + 1LoopDebug.Print "S="; sEnd Sub(2)Public Sub 改错8_3_2_求分式多项和()Dim nm, n, k ,p As integerDim y As Doublenm = Val(InputBox("请输入计算公式1后面的项目数目个数")) n = 1: p = 1: y = 1Do While n <= nmk = 2 * n + 1p = p * (k - 1) * ky = y + ((-1) ^ n) / pn = n + 1LoopDebug.Print "y="; yEnd Sub4.编程题(1)用if……else语句编程Public Sub分段函数1()Dim x, y, z As Doublex = Val(InputBox("请输入x的值:"))y = Val(InputBox("请输入y的值:"))If x > y And y <> 0 Thenz = x / yElseIf x = y Thenz = x * y * Sgn(y)Elsez = x + yEnd IfDebug.Print "x="; xDebug.Print "y="; yDebug.Print "z="; zEnd Sub(1)用select case语句结构编程Public Sub分段函数2()Dim x, y, z, a As Doublex = Val(InputBox("请输入x"))y = Val(InputBox("请输入y"))a = y - xSelect Case aCase Is > 0z = x + yDebug.Print zCase 0z = x * y * Sgn(y)Debug.Print zCase ElseIf y <> 0 Thenz = x / yDebug.Print zElseDebug.Print "z没有值"End IfEnd SelectEnd Sub(2)Public Sub 求解一元二次方程()Dim a, b, c As IntegerDim d, x1, x2, x3, x4 As Doublea = Val(InputBox("请输入a的整型数:"))b = Val(InputBox("请输入b的整型数:"))c = Val(InputBox("请输入c的整型数:"))d = b * b - 4 * a * cIf d > 0 Thenx1 = (-b + Sqr(d)) / (2 * a)x2 = (-b - Sqr(d)) / (2 * a)Debug.Print "x1="; x1, "x2="; x2Else if d=0 thenx3 = -b / (2 * a)x4 = -b/ (2 * a)Debug.Print "x3=";x3Debug.Print "x4=";x4ElseDebug.Print "方程没有实数解"End IfEnd Sub(3--1)用无条件转向语句GOTO编程Public Sub 数字与星期的转换1()Dim num As Integer10 num = Val(InputBox("请输入整数值:")) If num = 0 ThenDebug.Print "这是星期日"ElseIf num = 1 ThenDebug.Print "这是星期一"ElseIf num = 2 ThenDebug.Print "这是星期二"ElseIf num = 3 ThenDebug.Print "这是星期三"ElseIf num = 4 ThenDebug.Print "这是星期四"ElseIf num = 5 ThenDebug.Print "这是星期五"ElseIf num = 6 ThenDebug.Print "这是星期六"ElseIf num = -1 ThenDebug.Print "程序运行结束"EndElseDebug.Print "输入数据错误!"GoTo 10End IfEnd Sub(3--2)Public Sub数字与星期的转换2 ()Dim x As IntegerDo While Truex = Val(InputBox("请输入数字"))If x = 0 ThenDebug.Print "这是星期日"Exit DoElseIf x >= 1 And x <= 6 ThenDebug.Print "这是星期" + Str(x)Exit DoElseIf x = -1 ThenExit DoElseMsgBox ("输入数据错误!")End IfLoopEnd Sub(4)Public Sub 行李重量计费()Dim an, cn, weight, s_w, distance, fee As Doublean = Val(InputBox("请输入成年人数量"))cn = Val(InputBox("请输入未成年人数量"))weight = Val(InputBox("请输入行李重量"))distance = Val(InputBox("请输入距离"))s_w = weight - 20 * an - 10 * cnIf s_w <= 0 Thenfee = 0ElseIf distance / 100 = Int(distance / 100) Thenfee = 0.2 * s_w * (distance / 100)Elsefee = 0.2 * s_w * (Int(distance / 100) + 1) End IfEnd IfDebug.Print feeEnd Sub(5)Public Sub 求自然数的多项式和()Dim n, s As Integers = 0For n = 1 To 10s = s + (s + n)NextDebug.Print "S=1+(1+2)+(1+2+3)+...+1+2+3+...+10)="; s End SubRun:S=1+(1+2)+(1+2+3)+...+1+2+3+...+10)= 2036Public Sub 求多项自然数阶乘的和()Dim s, t As SingleDim n As Integert = 1s = 0For n = 1 To 20t = t * ns = s + tNextDebug.Print "1!+2!+3!+...+20!="; sEnd SubRun:1!+2!+3!+...+20!= 2.561327E+18(6)Public Sub 既能被3整除又能被5整除正整数个数() Dim i, x As Integerx = 0For i =100 To 200If i / 3 = Int(i / 3) And i / 5 = Int(i / 5) ThenDebug.Print ix = x + 1End IfNextDebug.Print "x="; xEnd SubRun:120135150165180195x= 7(7)Public Sub 输出直角三角形图案1()Dim i, j As IntegerFor i = 1 To 9Debug.PrintNextFor i = 1 To 4Debug.Print Tab(20); "*";For j = 1 To (2 * i - 2)Debug.Print "*";NextDebug.PrintNextEnd SubRun:****************Public Sub 输出直角三角形图案2() Dim i, j As IntegerFor i = 1 To 9Debug.PrintNextDebug.Print Tab(20); "*";For i = 1 To 4Debug.Print Tab(19 - i); "*";For j = 1 To (i + 1)Debug.Print "*";NextDebug.PrintNextEnd SubRun:*******************Public Sub 输出平行四边形图案() Dim i, j As IntegerFor i = 1 To 9Debug.PrintNextFor i = 1 To 5Debug.Print Tab(21 - i);For j = 1 To 6Debug.Print "*";NextDebug.PrintNextEnd SubRun:******************************(8)Public Sub 求选手获得的平均分()Dim score(1 To 11), minno, maxno, sum, aver As Single Dim i As Integerminno = 1maxno = 1sum = 0For i = 1 To 10score(i) = Val(InputBox("请输入选手的成绩值:")) Debug.Print score(i)NextFor i = 2 To 10If score(i) < score(minno) Thenminno = iEnd IfIf score(i) > score(maxno) Thenmaxno = iEnd IfNext iFor i = 1 To 10sum = sum + score(i)Next isum = sum - score(minno) - score(maxno)aver = sum / 8Debug.Print "该选手的平均分是:"; averEnd Sub(9)关于素数的求解(9-1)求100之内的所有素数Public Sub 求所有素数之和()Dim s, w, n As Integers = 0For w = 2 To 99 Step 2For n = 2 To Sqr(w)If w Mod n = 0 ThenExit ForEnd IfNextIf n > Sqr(w) Thens = s + wEnd IfDebug.Print "S="; sNextEnd Sub(9-2)Public Sub 求200以内的所有素数()Dim w, n As IntegerDebug.Print "200 以内的所有素数是:" For w = 2 To 199For n = 2 To Sqr(w)If w Mod n = 0 ThenExit ForEnd IfNext nIf n > Sqr(w) ThenDebug.Print w;End IfNextDebug.PrintEnd Sub(10)Public Sub 求水仙花数1()Dim i, j, k, n As IntegerDebug.Print "水仙花数是:"For i = 1 To 9For j = 0 To 9For k = 0 To 9n = i * 100 + j * 10 + kIf n = i * i * i + j * j * j + k * k * k ThenDebug.Print n;End IfNext kNext jNext iDebug.PrintEnd SubPublic Sub 求水仙花数2()Dim i, j, k, n As IntegerDebug.Print "水仙花数是:"For n = 150 To 999i = Int(n / 100)j = Int(n / 10 - i * 10)k = n Mod 10If n = i * i * i + j * j * j + k * k * k ThenDebug.Print n;End IfNextDebug.PrintEnd Subrun:水仙花数是:153 370 371 407(11)Public Sub 求分数数列和()Dim i, t, n As IntegerDim a, b, s As Singlen = 20a = 2:b = 1: s = 0For i = 1 To ns = s + a / bt = aa = a + bb = tNextDebug.Print "sum="; s;End Sub(12)Public Sub N年达到的利息()Dim y As IntegerDim interest1,interest As DoubleP=10000y = 0interest = 0Do Until interest >= 1000Interest1 =2*p* 0.0225 *(1-0.2) ‘一期2年整存整取扣税后的利息p=p+interest1 ‘扣税后的利息加上本金成为新一期的本金Interest=p-10000 ‘存款以来实际所的利息y = y + 2Debug.Print interest, yLoopEnd SubRun:360 2732.959999999999 4 1119.34656 6。
数据库原理与应用教程第四版 第八章答案
免责声明:私人学习之余整理,如有错漏,概不负责1.简述数据库设计过程。
需求分析、结构设计、行为设计、数据库实施、数据库库运行和维护2.数据库结构设计包含哪几个过程?概念结构、逻辑结构和物理机构3.需求分析中发现事实的方法有哪些?检查文档、面谈、观察业务的运转、研究、问卷调查4.数据库概念结构设计有哪些特点?丰富的语义表达能力、易于交流和理解、易于更改、易于向各种数据模型转换5.什么是数据库的逻辑结构设计?简述其设计步骤。
将概念设计产生的概念模型转换为具体的数据库管理系统支持的组织层数据模型概念结构转换为关系数据模型、对关系数据模型进行优化、设计面向用户的外模式6.把E-R模型转换为关系模式的转换规则有哪些?1)一个实体转换为一个关系模式2)1对1联系可以转换为独立的关系模式,也可以与任意一端对应的关系模式合并3)1对多联系可以转换为独立的关系模式,也可以与多端所对应的关系模式合并4)多对多联系必须转换为独立的关系模式5)三个或三个以上实体间的多元联系可以转换为一个关系模式6)具有相同主码的关系模式可以合并7.数据模型的优化包含哪些方法?1)确定各属性间的函数依赖关系2)对各个关系模式之间的书依赖进行极小化处理,消除冗余联系3)判断每个关系模式的范式,根据实际需要确定最合适的范式4)根据需求分析阶段得到的处理要求,确定是否对某些模式进行分解或合并8.合并为一个E-R图,转为符合第三范式的关系模式,说明主码外码关系模式如下(主码有下划线):职工(职工编号,姓名,性别,年龄,职务,部门)外码:部门部门(部门号,部门名,电话,地点)设备(设备号,名称,规格,价格,部门)外码:部门零件(零件号,零件名,规格,价格)厂商(厂商号,厂商名,电话,地址)生产表(厂商号,零件号,生产日期)外码:厂商号,零件号装备表(设备号,零件号,零件数量)外码:设备号,零件号9.建立描述顾客在商店的购物情况的数据库应用系统,该系统有如下要求:商店和顾客多对多,顾客每次购物有购物金额和购物日期,,每个客户每天在每个商店最多一次购物。
数据库技术与应用第8章 习题答案
第8章数据库恢复技术1. 试述事务的概念及事务的四个特性。
解:事务是用户定义的一个基本操作序列,这个基本操作序列可以包含一个或者多个数据库的基本操作。
事务所包含的基本操作要么都做,要么都不做,它们构成了一个不可分割的工作单元。
事务具有四个基本特性:原子性(Atomicity)、一致性(Consistency)、隔离性(Isolation)和持久性(Durability),简称为ACID特性。
2. 数据库运行中可能产生的故障有哪些?简述不同故障对数据库造成的影响有何不同。
解:数据库运行中可能发生各种各样的故障,大致分为以下几类:事务故障、系统故障、介质故障、其他一些因素导致的故障,如计算机病毒、操作失误等。
不同故障对数据库造成的影响不同,事务故障、系统故障影响事务的正常执行,介质故障和计算机病毒破坏数据库数据。
3. 恢复机制的基本思想是什么?恢复的实现技术有哪些?解:恢复机制的基本思想是:建立冗余数据;利用这些冗余数据实施数据库恢复。
数据转储和登录日志文件是建立冗余数据最常用的技术。
当系统运行过程中发生故障,利用转储的数据库后备副本和日志文件就可以将数据库恢复到故障前的某个一致性状态。
4. 什么是日志文件?日志文件的作用是什么?登记日志文件的原则是什么?解:日志文件是用来记录事务对数据库的更新操作的文件,是系统运行的历史记载。
日志文件的作用是:用来进行事务故障恢复和系统故障恢复,协助后备副本进行介质故障恢复。
登记日志文件必须要遵循两条原则:一是登记的次序严格按并发事务执行的时间次序。
二是必须先写日志文件,后写数据库。
5. 试述事务故障、系统故障、介质故障的恢复策略和方法。
解:●事务故障的恢复:事务故障的恢复是由系统自动完成的,对用户是透明的。
其过程如下:(1) 反向扫描文件日志(即从最后向前扫描日志文件),查找该事务的更新操作。
(2) 对该事务的更新操作执行逆操作。
(3) 继续反向扫描日志文件,查找该事务的其他更新操作,并做同样处理。
数据库第八章答案
4.设有函数依赖集F={AB→CE,A→C,GP→B,EP→A,CDE→P,HB→P,D→HG,ABC →PG},计算属性集D关于F的闭包D+。
解:令X={D},X(0)=D。
在F中找出左边是D子集的函数依赖,其结果是:D→HG,∴X(1)=X(0)HG=DGH,显然有X(1)≠X(0)。
在F中找出左边是DGH子集的函数依赖,未找到,则X(2)=DGH。
由于X(2)=X (1),则D+=DGH5求与F={A→C,C→A,B→AC,D→AC,BD→A}等价的最小相关性集合。
F->{A->C,C->A,B->C,D->C}9.设有关系模式R(U,F),其中:U={A,B,C,D,E},F={A→D,E→D,D→B,BC→D,DC→A}⑴求出R的候选关键字。
⑵判断p={AB,AE,CE,BCD,AC}是否为无损连接分解?解:⑴(CE)+=ABCDE,则CE→U,而C+=C,E+=DE=BDE,根据候选关键字定义,CE 是R的候选关键字。
⑵p的无损连接性判断表如下图所示,由此判断不具有无损连接性。
Ri A B C D EAB a1 a2AE a1 a5CE a3 a5BCD a2 a3 a4AC a1 a311、设有关系框架R(A,B,C,D,E,F)及其上的函数相关性集合F={A B,C F,E A,CE D}:(1)求出R的所有候选关键字。
(2)将R无损连接分解到BCNF.主属性CECE+=CEFABD候选关键字CER1={A,B}R2={C,F}R3={E,A}R4={C,E,D}。
数据库系统原理教程课后习题及答案(第八章)
第8章关系查询处理和查询优化1 .试述查询优化在关系数据库系统中的重要性和可能性。
答:重要性:关系系统的查询优化既是RDBMS 实现的关键技术又是关系系统的优点所在。
它减轻了用户选择存取路径的负担。
用户只要提出“干什么”,不必指出“怎么干”。
查询优化的优点不仅在于用户不必考虑如何最好地表达查询以获得较好的效率,而且在于系统可以比用户程序的“优化’夕做得更好。
可能性:这是因为:( l )优化器可以从数据字典中获取许多统计信息,例如关系中的元组数、关系中每个属性值的分布情况、这些属性上是否有索引、是什么索引(B +树索引还是HASH 索引或惟一索引或组合索引)等。
优化器可以根据这些信息选择有效的执行计划,而用户程序则难以获得这些信息。
( 2 )如果数据库的物理统计信息改变了,系统可以自动对查询进行重新优化以选择相适应的执行计划。
在非关系系统中必须重写程序,而重写程序在实际应用中往往是不太可能的。
( 3 )优化器可以考虑数十甚至数百种不同的执行计划,从中选出较优的一个,而程序员一般只能考虑有限的几种可能性。
( 4 )优化器中包括了很多复杂的优化技术,这些优化技术往往只有最好的程序员才能掌握。
系统的自动优化相当于使得所有人都拥有这些优化技术。
2 .对学生一课程数据库有如下的查询:SEI 王CT Cn 即ne FROM Student , Cou 拐e , SC WHERE Student . Sno = SC . Sno AND SC . Cllo = Coll 拐e . Cllo AND Stu 击nt . Sdept = ! 15 ! ; 此查询要求信息系学生选修了的所有课程名称。
试画出用关系代数表示的语法树,并用关系代数表达式优化算法对原始的语法树进行优化处理,画出优化后的标准语法树。
答:3 .试述查询优化的一般准则。
答:下面的优化策略一般能提高查询效率:( l )选择运算应尽可能先做;( 2 )把投影运算和选择运算同时进行;( 3 )把投影同其前或其后的双目运算结合起来执行;( 4 )把某些选择同在它前面要执行的笛卡儿积结合起来成为一个连接运算;( 5 )找出公共子表达式;( 6 )选取合适的连接算法。
实用数据库系统开发 第八章 课后习题答案
第八章教材jxsk8.1.1.1CREATE PROCEDURE Pro_Qsinf@Sno_in char(8)=’S2’,@Sname_out char(8) output,@Age_out int output,@Dept_out char(10) outputAs select @Sname_out=Sname,@Age_out=age,@Dept_out=deptFrom Student where sno=@Sno_inGO8.1.1.2USE jxskdeclare @Sno_in char(8),@Sname_out nvarchar(255),@Age_out int,@Dept_out nvarchar(255)exec Pro_Qsinf default,@Sname_out output,@Age_out output,@Dept_out outputprint @Sname_outprint @Age_outprint @Dept_outselect @Sno_in='S4'exec Pro_Qsinf @Sno_in,@Sname_out output,@Age_out output,@Dept_out outputprint @Sname_outprint @Age_outprint @Dept_outGo8.1.2.1USE jxskCREATE Procedure Pro_Qscore@Sname_in nvarchar(255),@Cname_in nvarchar(255),@Score_out float outputAs select @Score_out=Score from Student,Course,SCwhere Student.Sno=SC.Sno and o=o and Sname=@Sname_in and Cname=@Cname_in8.1.2.2USE jxskdeclare @Sname_in nvarchar(255),@Cname_in nvarchar(255),@Score_out floatselect @Sname_in='李思'select @Cname_in='程序设计'exec Pro_Qscore @Sname_in,@Cname_in,@Score_out outputprint Rtrim(@Sname_in)+'='+Ltrim(str(@Score_out))Go8.2.1CREATE PROCEDURE Pro_Qsinf@Sno_in char(2)='S2',@Sname_out char(8) output,@Age_out tinyint output,@Dept_out char(10) outputAs select @Sname_out=Sname,@Age_out=age,@Dept_out=deptfrom Student where sno=@Sno_inGO8.2.2Alter Procedure Pro_Qsinf@Sno_in char(2)='S1',@Sname_out char(8) output,@Sex_out char(2) output,@Dept_out char(10) outputASSelect @Sname_out=Sname,@Sex_out=Sex,@Dept_out=Deptfrom Student where Sno=@Sno_inGo8.3.2USE jxskDrop procedure Pro_QscoreGO习题Jiaoxuedb1.CREATE Procedure Pro_Qstuin@Sname_in char(8),@Cname_out char(8),@Score_out float,@Tname_out char(8) output AS select @Cname_out=Cname,@Score_out=Score,@Tname_out=Tnamefrom Student,Course,SC,Teacherwhere Student.Sno=SC.Sno and o=oand Sname=@Sname_inGO2.Create Procedure Pro_Qexage@Dept_in char(8),@Maxage_out float(8),@Minage_out float(8) outputAS select @Maxage_out=max(Age),@Minage_out=min(Age) from Studentwhere Dept=@Dept_inGO3.CREATE Procedure Pro_Qscore@Sname_in char(8),@Cname_in char(8),@Score_out float outputAs select @Score_out=Score from Student,Course,SCwhere Student.Sno=SC.Sno and o=oand Sname=@Sname_in and Cname=@Cname_inGO4.CREATE Procedure Pro_Qcount@Prof_in char(8),@count_out tinyint outputAs select @count_out=count(Tno) from Teacherwhere Prof=@Prof_ingroup by Profdeclare @Prof_in char(8),@count_out tinyintselect @Prof_in='副教授'exec Pro_Qcount @Prof_in,@count_out outputprint Rtrim(@Prof_in)+'='+Ltrim(str(@count_out))GO5.CREATE Procedure Pro_Qtdata@Prof_in char(8),@count_out tinyint,@Avgage_out int,@Avgsal_out float,@Maxsal_out float outputAs select @count_out=count(Tno),@Avgage_out=avg(Age),@Avgsal_out=avg(Sal),@Maxsal_out=max( Sal) from Teacherwhere Prof=@Prof_ingroup by ProfGO6.CREATE Procedure Pro_Qdept@dept_in char(16) ,@tcount_out int,@tavgage_out int,@scount_out int As select @tcount_out=count(Tno),@tavgage_out=avg(Teacher.Age),@scount_out=count(Sno) from Teacher,Studentwhere Teacher.Dept=@dept_in and Teacher.Dept=Student.Deptgroup by Teacher.DeptGO7.CREATE Procedure Pro_Qsc@Cname_in char(8),@Sname_out char(8),@dept_out char(16),@score_out float As select @Sname_out=Sname,@dept_out=Dept,@score_out=Score from Student,SC,Coursewhere o=o and SC.Sno=Student.Sno and Cname=@Cname_in GOdeclare @Cname_in char(8),@Sname_out char(8),@dept_out char(16),@score_out float select @Cname_in='程序设计'exec Pro_Qsc @Sname_out,@dept_out,@score_outprint Rtrim(@Cname_in)+' '+Ltrim(str(@Sname_out))+' '+Ltrim(str(@dept_out))+' '+Ltrim(str(@score_out))GO8.use jiaoxuedbCREATE Procedure Pro_Qstc@tname_in char(8),@cname_in char(8),@tcname_out char(8),@thour_out int,@ccount_out int,@avgscore_out int,@maxscore_out intas select @cname_out =Cname,@thour_out=sum(Chour),@ccount_out=count(Sno),@avgscore_out=avg(Score),@m axscore=max(Score)from Course,SC,TCwhere Tname=@tname_in,Cname=@cname_ingroup by CnoGOdeclare @tname_in char(8),@cname_in char(8),@tcname_out char(8),@thour_out int,@ccount_out int,@avgscore_out int,@maxscore_out intselect @tname_in='赵策'select @cname_in='计算机网络'exec Pro_Qstc @tname_in, @cname_in, @tcname_out, @thour_out, @ccount_out, @avgscore_out, @maxscore_outprint Rtrim(@tname_in)+' '+Ltrim(@cname_in)+' '+Ltrim(@tcname_out)+' '+Ltrim(@thour_out)+' '+Ltrim(@ccount_out)+' '+Ltrim(@avgscore_out)+''+Ltrim(@maxscore_out)GO8.Drop Procedure Pro_QstuinGO9.Drop Procedure Pro_QscoreDrop Procedure Pro_QcountGO。
第八章 数据库并发控制练习和答案
第八章数据库并发控制一、选择题1.为了防止一个用户得工作不适当地影响另一个用户,应该采取( )。
A、完整性控制B、访问控制C、安全性控制D、并发控制2、解决并发操作带来得数据不一致问题普遍采用()技术。
A、封锁B、存取控制C、恢复D、协商3.下列不属于并发操作带来得问题就是( )。
A、丢失修改B、不可重复读C、死锁D、脏读4.DBMS普遍采用( )方法来保证调度得正确性。
A、索引B、授权C、封锁D、日志5.事务T在修改数据R之前必须先对其加X锁,直到事务结束才释放,这就是()。
A、一级封锁协议B、二级封锁协议C、三级封锁协议D、零级封锁协议6.如果事务T获得了数据项Q上得排她锁,则T对Q( )。
A、只能读不能写B、只能写不能读C、既可读又可写D、不能读也不能写7。
设事务T1与T2,对数据库中地数据A进行操作,可能有如下几种情况,请问哪一种不会发生冲突操作() .A、T1正在写A,T2要读AB、T1正在写A,T2也要写AC、T1正在读A,T2要写AD、T1正在读A,T2也要读A8。
如果有两个事务,同时对数据库中同一数据进行操作,不会引起冲突得操作就是() .A、一个就是DELETE,一个就是SELECTB、一个就是SELECT,一个就是DELETEC、两个都就是UPDATED、两个都就是SELECT9.在数据库系统中,死锁属于()。
A、系统故障B、事务故障C、介质故障D、程序故障二、简答题1、在数据库中为什么要并发控制?答:数据库就是共享资源,通常有许多个事务同时在运行。
当多个事务并发地存取数据库时就会产生同时读取与/或修改同一数据得情况.若对并发操作不加控制就可能会存取与存储不正确得数据,破坏数据库得一致性。
所以数据库管理系统必须提供并发控制机制。
2、并发操作可能会产生哪几类数据不一致?用什么方法能避免各种不一致得情况?答: 并发操作带来得数据不一致性包括三类:丢失修改、不可重复读与读“脏”数据.(1)丢失修改(LostUpdate)两个事务T1与T2读入同一数据并修改,T2提交得结果破坏了(覆盖了)T1提交得结果,导致T1得修改被丢失。
数据库系统概念(databasesystemconcepts)英文第六版课后练习题答案第8章
C H A P T E R8Relational Database DesignExercises8.1Suppose that we decompose the schema R=(A,B,C,D,E)into(A,B,C)(A,D,E).Show that this decomposition is a lossless-join decomposition if thefollowing set F of functional dependencies holds:A→BCCD→EB→DE→AAnswer:A decomposition{R1,R2}is a lossless-join decomposition ifR1∩R2→R1or R1∩R2→R2.Let R1=(A,B,C),R2=(A,D,E),and R1∩R2= A.Since A is a candidate key(see PracticeExercise8.6),Therefore R1∩R2→R1.8.2List all functional dependencies satis?ed by the relation of Figure8.17.Answer:The nontrivial functional dependencies are:A→B andC→B,and a dependency they logically imply:AC→ B.There are19trivial functional dependencies of the form?→?,where???.Cdoes not functionally determine A because the?rst and third tuples havethe same C but different A values.The same tuples also show B does notfunctionally determine A.Likewise,A does not functionally determineC because the?rst two tuples have the same A value and different Cvalues.The same tuples also show B does not functionally determine C.8.3Explain how functional dependencies can be used to indicate the fol-lowing:910Chapter8Relational Database DesignA one-to-one relationship set exists between entity sets student andinstructor.A many-to-one relationship set exists between entity sets studentand instructor.Answer:Let Pk(r)denote the primary key attribute of relation r.The functional dependencies Pk(student)→Pk(instructor)andPk(instructor)→Pk(student)indicate a one-to-one relationshipbecause any two tuples with the same value for student must havethe same value for instructor,and any two tuples agreeing oninstructor must have the same value for student.The functional dependency Pk(student)→Pk(instructor)indicates amany-to-one relationship since any student value which is repeatedwill have the same instructor value,but many student values mayhave the same instructor value.8.4Use Armstrong’sa xioms to prove the soundness of the union rule.(Hint:Use the augmentation rule to show that,if?→?,then?→??.Apply theaugmentation rule again,using?→?,and then apply the transitivityrule.)Answer:To prove that:if?→?and?→?then?→??Following the hint,we derive:→?given→??augmentation rule→??union of identical sets→?given→??augmentation rule→??transitivity rule and set union commutativity8.5Use Armstrong’sa xioms to prove the soundness of the pseudotransitiv-ity rule.a xioms of the Pseudotransitivity Rule:Answer:Proof using Armstrong’sif?→?and??→?,then??→?.→?given→??augmentation rule and set union commutativity ?→?given→?transitivity rule8.6Compute the closure of the following set F of functional dependenciesfor relation schema R=(A,B,C,D,E).Exercises11A→BCCD→EB→DE→AList the candidate keys for R.Answer:Note:It is not reasonable to expect students to enumerate all of F+.Some shorthand representation of the result should be acceptable as long as the nontrivial members of F+are found.Starting with A→BC,we can conclude:A→B and A→ C.Since A→B and B→D,A→D(decomposition,transitive) Since A→C D and C D→E,A→E(union,decom-position,transi-tive)Since A→A,we have(re?exive)A→ABC DE from the above steps(union)Since E→A,E→ABC DE(transitive)Since C D→E,C D→ABC DE(transitive)Since B→D and BC→C D,BC→ABC DE (augmentative, transitive)Also,C→C,D→D,B D→D,etc.Therefore,any functional dependency with A,E,BC,or C D on the left hand side of the arrow is in F+,no matter which other attributes appear in the FD.Allow*to represent any set of attributes in R,then F+isB D→B,B D→D,C→C,D→D,B D→B D,B→D,B→B,B→B D,and all FDs of the form A?→?,BC?→?,C D?→?,E?→?where?is any subset of{A,B,C,D,E}.Thecandidate keys are A,BC,C D,and E.8.7Using the functional dependencies of Practice Exercise8.6,compute thecanonicalcover F c.Answer:The given set of FDs F is:-A→BCCD→EB→DE→AThe left side of each FD in F is unique.Also none of the attributes in the left side or right side of any of the FDs is extraneous.Therefore the canonical cover F c is equal to F.12Chapter8Relational Database Design8.8Consider the algorithm in Figure8.18to compute?+.Show that thisalgorithm is more ef?cient than the one presented in Figure8.8(Sec-tion8.4.2)and that it computes?+correctly.Answer:The algorithm is correct because:If A is added to result then there is a proof that?→ A.To see this,observe that?→?trivially so?is correctly part of result.IfA∈?is added to result there must be some FD?→?such thatA∈?and?is already a subset of result.(Otherwise f dcountwould be nonzero and the if condition would be false.)A full proofcan be given by induction on the depth of recursion for an executionof addin,but such a proof can be expected only from students witha good mathematical background.If A∈?+,then A is eventually added to result.We prove this byinduction on the length of the proof of?→A using Armstrong’saxioms.First observe that if procedure addin is called with someargument?,all the attributes in?will be added to result.Also if aparticular FD’sfdcount becomes0,all the attributes in its tail willde?nitely be added to result.The base case of the proof,A∈??A∈?+,is obviously true because the?rst call to addinhas the argument?.The inductive hypotheses is that if?→A canbe proved in n steps or less then A∈result.If there is a proof inn+1steps that?→A,then the last step was an application ofeither re?exivity,augmentation or transitivity on a fact?→?proved in n or fewer steps.If re?exivity or augmentation was usedin the(n+1)st step,A must have been in result by the end of the n thstep itself.Otherwise,by the inductive hypothesis??result.Therefore the dependency used in proving?→?,A∈?willhave f dcount set to0by the end of the n th step.Hence A will beadded to result.To see that this algorithm is more ef?cient than the one presented inthe chapter note that we scan each FD once in the main program.Theresulting array appears has size proportional to the size of the givenFDs.The recursive calls to addin result in processing linear in the sizeof appears.Hence the algorithm has time complexity which is linear inthe size of the given FDs.On the other hand,the algorithm given in thetext has quadratic time complexity,as it may perform the loop as manytimes as the number of FDs,in each loop scanning all of them once.8.9Given the database schema R(a,b,c),and a relation r on the schema R,write an SQL query to test whether the functional dependency b→cholds on relation r.Also write an SQL assertion that enforces the func-tional dependency.Assume that no null values are present.(Althoughpart of the SQL standard,such assertions are not supported by anydatabase implementation currently.)Answer:Exercises13a.The query is given below.Its result is non-empty if and only ifb→c does not hold on r.select bfrom rgroup by bhaving count(distinct c)>1b.create assertion b to c check(not exists(select bfrom rgroup by bhaving count(distinct c)>1))8.10Our discussion of lossless-join decomposition implicitly assumed thatattributes on the left-hand side of a functional dependency cannot take on null values.What could go wrong on decomposition,if this property is violated?Answer:The natural join operator is de?ned in terms of the cartesian product and the selection operator.The selection operator,gives unknown for any query on a null value.Thus,the natural join excludes all tuples with null values on the common attributes from the?nal result.Thus, the decomposition would be lossy(in a manner different from the usual case of lossy decomposition),if null values occur in the left-hand side of the functional dependency used to decompose the relation.(Null values in attributes that occur only in the right-hand side of the functionaldependency do not cause any problems.)8.11In the BCNF decomposition algorithm,suppose you use a functional de-pendency?→?to decompose a relation schema r(?,?,?)into r1(?,?) and r2(?,?).a.What primary and foreign-key constraint do you expect to holdon the decomposed relations?b.Give an example of an inconsistency that can arise due to anerroneous update,if the foreign-key constraint were not enforcedon the decomposed relations above.c.When a relation is decomposed into3NF using the algorithm inSection8.5.2,what primary and foreign key dependencies wouldyou expect will hold on the decomposed schema?14Chapter8Relational Database DesignAnswer:a.?should be a primary key for r1,and?should be the foreign keyfrom r2,referencing r1.b.If the foreign key constraint is not enforced,then a deletion of atuple from r1would not have a corresponding deletion from thereferencing tuples in r2.Instead of deleting a tuple from r,thiswould amount to simply setting the value of?to null in sometuples.c.For every schema r i(??)added to the schema because of a rule→?,?should be made the primary key.Also,a candidate key?for the original relation is located in some newly created relationr k,and is a primary key for that relation.Foreign key constraints are created as follows:for each relationr i created above,if the primary key attributes of r i also occur inany other relation r j,then a foreign key constraint is created fromthose attributes in r j,referencing(the primary key of)r i.8.12Let R1,R2,...,R n be a decomposition of schema U.Let u(U)be a rela-(u).Show thattion,and let r i=RIu?r11r21···1r nAnswer:Consider some tuple t in u.(u)implies that t[R i]∈r i,1≤i≤n.Thus,Note that r i=Rit[R1]1t[R2]1...1t[R n]∈r11r21...1r nBy the de?nition of natural join,t[R1]1t[R2]1...1t[R n]=(??(t[R1]×t[R2]×...×t[R n])) where the condition?is satis?ed if values of attributes with the samename in a tuple are equal and where?=U.The cartesian productof single tuples generates one tuple.The selection process is satis?edbecause all attributes with the same name must have the same valuesince they are projections from the same tuple.Finally,the projectionclause removes duplicate attribute names.By the de?nition of decomposition,U=R1∪R2∪...∪R n,which meansthat all attributes of t are in t[R1]1t[R2]1...1t[R n].That is,t is equalto the result of this join.Since t is any arbitrary tuple in u,u?r11r21...1r n8.13Show that the decomposition in Practice Exercise8.1is not a dependency-preserving decomposition.Answer:The dependency B→D is not preserved.F1,the restrictionof F to(A,B,C)is A→ABC,A→AB,A→AC,A→BC,Exercises15 A→B,A→C,A→A,B→B,C→C,AB→AC,AB→ABC,AB→BC,AB→AB,AB→A,AB→B,AB→C,AC(same as AB),BC(same as AB),ABC(same as AB).F2,the restriction of F to (C,D,E)is A→ADE,A→AD,A→AE,A→DE,A→A, A→D,A→E,D→D,E(same as A),AD,AE,DE,ADE(same as A).(F1∪F2)+is easily seen not to contain B→D since the only FD in F1∪F2with B as the left side is B→B,a trivial FD.We shall see in Practice Exercise8.15that B→D is indeed in F+.Thus B→D is not preserved.Note that C D→ABC DE is also not preserved.A simpler argument is as follows:F1contains no dependencies with D on the right side of the arrow.F2contains no dependencies withB on the left side of the arrow.Therefore for B→D to be preserved there mustbe an FD B→?in F+1and?→D in F+2(so B→D would followby transitivity).Since the intersection of the two schemes is A,?= A.Observe that B→A is not in F+1since B+=B D.8.14Show that it is possible to ensure that a dependency-preserving decom-position into3NF is a lossless-join decomposition by guaranteeing that at least one schema contains a candidate key for the schema being decom-posed.(Hint:Show that the join of all the projections onto the schemas of the decomposition cannot have more tuples than the original relation.)Answer:Let F be a set of functional dependencies that hold on a schema R.Let?={R1,R2,...,R n}be a dependency-preserving3NF decompo-sition of R.Let X be a candidate key for R.Consider a legal instance r of R.Let j=X(r)1R1(r)1R2(r) (1)R n(r).We want to prove that r=j.We claim that if t1and t2are two tuples in j such that t1[X]=t2[X],then t1=t2.To prove this claim,we use the following inductive argument–Let F′=F1∪F2∪...∪F n,where each F i is the restriction of F to the schema R i in?.Consider the use of the algorithm given in Figure8.8to compute the closure of X under F′.We use induction on the number of times that the f or loop in this algorithm is executed.Basis:In the?rst step of the algorithm,result is assigned to X,and hence given that t1[X]=t2[X],we know that t1[result]=t2[result] is true.Induction Step:Let t1[result]=t2[result]be true at the end of thek th execution of the f or loop.Suppose the functional dependency considered in the k+1thexecution of the f or loop is?→?,and that??result.??result implies that t1[?]=t2[?]is true.The facts that?→?holds forsome attribute set R i in?,and that t1[R i]and t2[R i]are in R i(r)imply that t1[?]=t2[?]is also true.Since?is now added to result by the algorithm,we know that t1[result]=t2[result]is true at the end of the k+1th execution of the f or loop.16Chapter8Relational Database DesignSince?is dependency-preserving and X is a key for R,all attributes in Rare in result when the algorithm terminates.Thus,t1[R]=t2[R]is true,that is,t1=t2–as claimed earlier.Our claim implies that the size of X(j)is equal to the size of j.Notealso that X(j)=X(r)=r(since X is a key for R).Thus we haveproved that the size of j equals that of ing the result of PracticeExercise8.12,we know that r?j.Hence we conclude that r=j.Note that since X is trivially in3NF,?∪{X}is a dependency-preservinglossless-join decomposition into3NF.8.15Give an example of a relation schema R′and set F′of functional depen-dencies such that there are at least three distinct lossless-join decompo-sitions of R′into BCNF.Answer:Given the relation R′=(A,B,C,D)the set of functionaldependencies F′=A→B,C→D,B→C allows three distinctBCNF decompositions.R1={(A,B),(C,D),(B,C)}is in BCNF as isR2={(A,B),(C,D),(A,C)}R2={(A,B),(C,D),(A,C)}R3={(B,C),(A,D),(A,B)}8.16Let a prime attribute be one that appears in at least one candidate key.Let?and?be sets of attributes such that?→?holds,but?→?does not hold.Let A be an attribute that is not in?,is not in?,and forwhich?→A holds.We say that A is transitively dependent on?.Wecan restate our de?nition of3NF as follows:A relation schema R is in3NF with respect to a set F of functional dependencies if there are nononprime attributes A in R for which A is transitively dependent on akey for R.Show that this new de?nition is equivalent to the original one.Answer:Suppose R is in3NF according to the textbook de?nition.Weshow that it is in3NF according to the de?nition in the exercise.Let A bea nonprime attribute in R that is transitively dependent on a key?forR.Then there exists??R such that?→A,?→?,A∈?,A∈,and?→?does not hold.But then?→A violates the textbookde?nition of3NF sinceA∈?implies?→A is nontrivialSince?→?does not hold,?is not a superkeyA is not any candidate key,since A is nonprimeExercises17Now we show that if R is in3NF according to the exercise de?nition,it is in3NF according to the textbook de?nition.Suppose R is not in3NF according the the textbook de?nition.Then there is an FD?→?that fails all three conditions.Thus?→?is nontrivial.?is not a superkey for R.Some A in?-?is not in any candidate key.This implies that A is nonprime and?→ A.Let?be a candidate key for R.Then?→?,?→?does not hold(since?is not a superkey), A∈?,and A∈?(since A is nonprime).Thus A is transitivelydependent on?,violating the exercise de?nition.8.17A functional dependency?→?is called a partial dependency if thereis a proper subset?of?such that?→?.We say that?is partially dependent on?.A relation schema R is in second normal form(2NF)if each attribute A in R meets one of the following criteria:It appears in a candidate key.It is not partially dependent on a candidate key.Show that every3NF schema is in2NF.(Hint:Show that every partial dependency is a transitive dependency.)Answer:Referring to the de?nitions in Practice Exercise8.16,a relation schema R is said to be in3NF if there is no non-prime attribute A in R for which A is transitively dependent on a key for R.We can also rewrite the de?nition of2NF given here as:“Arelation schema R is in2NF if no non-prime attribute A is partiallydependent on any candidate key for R.”To prove that every3NF schema is in2NF,it suf?ces to show that if a non-prime attribute A is partially dependent on a candidate key?,thenA is also transitively dependent on the key?.Let A be a non-prime attribute in R.Let?be a candidate key for R.Suppose A is partially dependent on?.From the de?nition of a partial dependency,we know that for someproper subset?of?,?→ A.Since???,?→?.Also,?→?does not hold,since?is acandidate key.Finally,since A is non-prime,it cannot be in either?or?.Thus we conclude that?→A is a transitive dependency.Hence we have proved that every3NF schema is also in2NF.8.18Give an example of a relation schema R and a set of dependencies suchthat R is in BCNF but is not in4NF.18Chapter8Relational Database DesignAnswer:R(A,B,C)A→→BExercises19result:=?;/*fdcount is an array whose ith element contains the number of attributes on the left side of the ith FD that arenot yet known to be in?+*/for i:=1to|F|dobeginlet?→?denote the ith FD;fdcount[i]:=|?|;end/*appears is an array with one entry for each attribute.The entry for attribute A is a list of integers.Each integeri on the list indicates that A appears on the left sideof the i th FD*/for each attribute A dobeginappears[A]:=NI L;for i:=1to|F|dobeginlet?→?denote the ith FD;if A∈?then add i to appears[A];endendaddin(?);return(result);procedure addin(?);for each attribute A in?dobeginif A∈result thenbeginresult:=result∪{A};for each element i of appears[A]dobeginfdcount[i]:=fdcount[i]-1;if fdcount[i]:=0thenbeginlet?→?denote the ith FD;addin(?);endendendendFigure8.18.An algorithm to compute?+.。
数据库第八章习题答案
第八章习题一、选择填空1.下列对派生类的描述中,( )是错的。
A.一个派生类可以作为另一个派生类的基类;B.派生类至少有一个基类;C.派生类的成员除了它自己的成员以外,还包含了它的基类的成员;D.派生类中继承的基类成员的访问权限到派生类保持不变。
2.派生类的对象对它的基类成员中( )是可以访问的。
A.公有继承的公有成员;B.公有继承的私有成员;C.公有继承的保护成员;D.私有继承的公有成员。
3.对基类和派生类的关系的描述中,( )是错的。
A.派生类是即类的具体化;B.派生类是基类的子集;C.派生类是基类定义的延续;D.派生类是基类的组合。
4.派生类的构造函数的成员初始化列中,不能包含( )。
A.基类的构造函数;B.派生类中子对象的初始化;C.基类的子对象的初始化;D.派生类中一般数据成员的初始化。
5.关于子类型的描述中,( )是错误的。
A.子类型就是指派生类是基类的子类型;B.一种类型当它至少提供了另一种类型的行为,则这种类型是另一种类型的子类型;C.在公有继承下,派生类是基类的子类型;D.子类型关系是不可逆的。
6.关于多继承二义性的描述中,( )是错误的。
A.一个派生类的两个基类中都有某个同名成员,在派生类中对该成员的访问可能出现二义性;B.解决二义性的最常用的方法是对成员名的限定法;C.基类和派生类中同时出现的同名函数,也存在二义性问题;D.一个派生类是从两个基类派生来的,而这两个基类又有一个共同的基类,对该基类的成员进行访问时也可能出现二义性。
7.设置虚基类的目的是( )。
A.简化程序;B.消除二义性;C.提高运行效率;D.减少目标代码8.带有虚基类的多层派生类构造函数的成员初始化列表中都要列出虚基类的构造函数,这样将对虚基类的子对象初始化( )。
A.与虚基类下面的派生类个数有关;B.多次;C.二次;D.一次9.若类A和类B的定义如下:class A{int i,j;public:void get();//……};class B:A{int k;public:void make();//…….};void B::make(){k=i*j;}则上述定义中,()是非法的表达式。
数据库,第8、9章DOC
第8章模块与VBA 编程基础一、选择题(1)下列能够交换变量X和Y值的程序段是( )。
A)Y=X:X=YB)Z=X:Y=Z:X=YC)Z=X:X=Y:Y=ZD)Z=X:W=Y:Y=Z:X=Y(2)在VBA中,下列关于过程的描述正确的是( )。
A)过程的定义可以嵌套,但过程的调用不能嵌套B)过程的定义不可以嵌套,但过程的调用可以嵌套C)过程的定义和过程的调用均可以嵌套D)过程的定义和过程的调用均不能嵌套(3)若要在子过程Proc1 调用后返回两个变量的结果,下列过程定义语句中有效的是( )。
A)Sub Proc1(n,m)B)Sub Procl(ByVal n,m)C)Sub Proc1(n,BYVal m)D)Sub Proc1(ByVal n, ByVal m)(4)Sub 过程与Function 过程最根本的区别是( )。
A)Sub 过程的过程名不能返回值,而Function 的过程名可以返回值B)Sub 过程可以使用Call 语句或直接使用过程名调用,而Function 过程不可以C)两种过程参数的传递方式不同D)Function 过程可以有参数,Sub 过程不可以有参数(5)能被"对象所识别的动作"和"对象可执行的活动"分别称为对象的( )。
A)方法和事件B)事件和方法C)事件和属性D)过程和方法(6)键盘事件是操作键盘所引发的事件,下列不属于键盘事件的是( )。
A)"击键"事件B)"键按下"事件C)"键释放"事件D)"键锁定"事件(7)VBA 程序的多条语句可以写在一行中,其分隔符必须使用符号( )。
A):B)'C);D),(8)下列数据类型中,不属于VBA数据类型的是( )。
A)长整型B)布尔型C)变体型D)指针型9)如下程序段定义了学生成绩的记录类型,由学号、姓名和三门课程成绩(百分制)组成。
数据库第八章课后答案
1、掌握事务的概念和特性。
事务是DBMS的基本工作单位,它是用户定义的一组逻辑一致的程序序列。
它是一个不可分割的工作单位,其中包含的所有操作,要么都执行,要么都不执行。
事务的特性即ACID特性:原子性、一致性、隔离性和持续性。
2、并发操作会产生几种不一致情况?用什么方法避免各种不一致的情况?操作可能会产生丢失修改、不能重复读和读“脏”数据这三种不一致情况。
采用封锁机制来进行并发控制,可避免各种不一致情况。
3、叙述数据库中数据的一致性问题。
在数据库的并发控制中,数据一致性问题有三个:丢失修改,不能重复读和读“脏”数据。
丢失修改是指T1和T2先后读取了同一个数据,T1把数据修改了并写回库中,T2也将读取的数据修改了并写回库中。
这样,T2提交的结果导致T1对数据库的修改丢失了。
不能重复读是指T1读取A,B两个数据并进行了运算之后,T2读了其中的数据B,把它修改后写回数据库,最后当T1为了对读取值进行校对而再重读B时,读的是T2修改后的值而不是T1开始读的值。
读“脏”数据是指T1修改了某一数据,并将其写回库中,T2读了这修改后的数据,而事务T1由于某种原因撤消了,被它修改的数据恢复了原来的值,这时,T2读的数据就与库中的数据不一致了,即T2读了不正确的数据,也称为T2读了“脏”数据。
4、叙述数据库中死锁产生的原因和解决死锁的方法。
锁产生的原因:封锁可以引起死锁。
比如事务T1封锁了数据A,事务T2封锁了数据B。
T1又申请封锁数据B,但因B被T2封锁,所以T1只能等待。
T2又申请封锁数据A,但A已被T1封锁,所以也处于等待状态。
这样,T1和T2处于相互等待状态而均不能结束,这就形成了死锁。
解决死锁的常用方法有如下三种:(1)要求每个事务一次就要将它所需要的数据全部加锁。
(2)预先规定一个封锁顺序,所有的事务都要按这个顺序实行封锁。
(3)允许死锁发生,当死锁发生时,系统就选择一个处理死锁代价小的事务,将其撤消,释放此事务持有的所有的锁,使其他事务能继续运行下去。
数据库原理A知到章节答案智慧树2023年南华大学
数据库原理A知到章节测试答案智慧树2023年最新南华大学第一章测试1.数据库系统的体系结构是()。
参考答案:三级模式结构和二级映像2.下列四项中,不属于数据库特点的是()。
参考答案:数据不丢失3.D BS中,内外存数据交换最终是通过()。
参考答案:OS完成4.逻辑数据独立性是指()。
参考答案:模式变,应用程序不变5.子模式是()。
参考答案:模式的逻辑子集6.应用数据库的主要目的是为了()。
参考答案:解决数据共享问题7.数据库管理系统是数据库系统的核心,它负责有效地组织、存储、获取和管理数据,属于一种(),是位于用户与操作系统之间的一层数据管理软件。
参考答案:系统软件8.数据库系统的数据独立性是指()。
参考答案:不会因为系统数据存储结构与数据逻辑结构的变化而影响应用程序9.在D BS中,D BM S和OS之问的关系是()。
参考答案:D BM S调用OS10.单个用户使用的数据视图的描述称为()。
参考答案:外模式第二章测试1. 在数据建模过程中,独立于计算机系统的模型是()。
参考答案:E-R模型2. 下列数据模型中,数据独立性最高的是()参考答案:关系数据模型3.在关系数据库中,模式对应的是()。
参考答案:基本表4. 当前应用最广泛的组织层数据模型是()。
参考答案:关系模型5.数据模式是()参考答案:记录类型及其联系的集合6. 概念模型独立于()。
参考答案:硬件设备和DBMS7.下列关于概念层数据模型的说法,错误的是()。
参考答案:在进行概念层数据模型设计时,需要考虑具体的DBMS的特点8. 下列关于E-R模型中联系的说法,错误的是()。
参考答案:一个联系最多只能关联2个实体9. 数据库中的数据模型三要素是指()。
参考答案:数据结构、数据操作和数据完整性约束10. 层次模型和网状模型是联系是通过指针实现的,关系数据库在物理层也使用指针。
()参考答案:对第三章测试1.对于关系数据库来讲,下面()的说法是错误的。
数据库系统原理及应用教程第四版课后答案(苗雪兰 刘瑞新) 机械工业出版社第8章
8.27 为什么要进行数据库转储,比较各种数据转储方法? 答: 所谓转储即DBA定期地将整个数据库复制到磁带或另一个磁盘上保存 起来的过程。这些备用的数据文本称为后备副本或后援副本。当数据 库遭到破坏后可以将后备副本重新装入,但重装后备副本只能将数据 库恢复到转储时的状态,要想恢复到故障发生时的状态,必须重新运 行自转储以后的所有更新事务。 转储可分为静态转储和动态转储。静态转储是在系统中无运行事务时 进行的转储操作。显然,静态转储得到的一定是一个数据一致性的副 本,转储简单,但转储必须等待正运行的用户事务结束才能进行,会降 低数据库的可用性。动态转储是指转储期间允许对数据库进行存取或 修改。必须把转储期间各事务对数据库的修改活动登记下来,建立日 志文件,后援副本加上日志文件就能把数据库恢复到某一时刻的正确 状态。 转储还可以分为海量转储和增量转储两种方式。海量转储是指每次转 储全部数据库。增量转储则指每次只转储上一次转储后更新过的数据。 从恢复角度看,使用海量转储得到的后备副本进行恢复一般说来会更 方便些。但如果数据库很大,事务处理又十分频繁,则增量转储方式 更实用更有效。
8.13答: 基本的封锁类型有两种:排它锁(简称X锁)和共享锁(简 称S锁)。 排它锁也称为独Байду номын сангаас或写锁。一旦事务T对数据对象A加上排 它锁,则只允许T读取和修改A,其他任何事务既不能读取 和修改A,也不能再对A加任何类型的锁,直到T释放A上的 锁为止。 共享锁又称读锁。如果事务T对数据对象A加上共享锁,其 他事务只能再对A加S锁,不能加X锁,知道事务T释放A上 的S锁为止。 8.14答: 封锁机制作为并发控制的重要手段,利用封锁的特性和封锁 协议,它在并发操作保证事务的隔离性,用正确的方式调度 并发操作,是一个用户事务的执行不受其他事务的干扰,从 而避免造成数据的不一致性。
《数据库原理与应用(SQL Server 2005)》第八章数据查询课后答案
7、select top 10 productid,productname,unitprice from products
order by unitprice
8、select * from products
select categoryid, count(categoryid) as '产品数量',avg(unitprice) as '平均价格',max(unitprice) as '最高价格'
in(select supplierid from suppliers where country='USA')
17.
select e1.employeeid,stname,e2.ReportsTo from employees as e1 left join employees as e2 on e1.employeeid=e2.ReportsTo
参考答案:
select e2.employeeid,stname from employees as e1 right join employees as e2 on e1.employeeid=e2.ReportsTo
更改后的第十七题的答案:select e1.employeeid, stname ,e1.title,count(e2.reportsto) as '下属个数'
from employees as e1 left join employees as e2 on e1.employeeid=e2.ReportsTo
group by e1.employeeid,stname,e1.title
18.
数据库课后题答案 第八章 管理SQL Server的安全性
第八章SQL Server的安全性要点:SQL Server 2000两级权限管理机制登陆帐户和服务器角色数据库用户和数据库角色权限的管理第一节SQL Server 2000安全性概述作为一种数据库管理系统,SQL Server2000系统中存储了用户大量的业务数据,这些数据都是用户的商业机密。
这些商业数据必须得到安全保障。
安全性管理是数据库管理系统的一个重要组成部分。
安全性就是确保只有授权的用户才能使用数据库中的数据和执行相应的操作,安全性管理包括两个方面的内容,一是用户能否登录系统和如何登录的管理,二是用户能否使用数据库中的对象和执行相应操作的管理。
SQL Server2000提供了一套完整的安全机制。
一、认证进程和认证模式认证进程就是指当用户访问数据库系统时,系统对该用户帐号和口令的确认过程,认证的内容包括确认用户的帐号是否有效、是否能访问系统、能访问系统中的哪些数据等。
认证模式就是指系统选择何种认证进程确认用户的方式。
用户必须使用一个登录帐号,才能连接到SQL Server系统中。
SQL Server 系统通过两种认证进程来确认用户的身份,这两种认证进程是:(1)WINDOWS认证进程(2)SQL Server认证进程当SQL Server在WINDOWS环境中运行时,系统管理员必须指定系统的认证模式类型。
认证模式类型有两种:(1)WINDOWS认证模式(2)混合模式WINDOWS认证模式只允许使用WINDOWS认证进程。
这时,用户不能指SQL Server的登录帐号。
混合认证模式既允许使用WINDOWS认证进程,又允许使用SQL Server认证进程。
在混合认证模式中,当某个用户希望登录SQL Server系统时,系统是采用WINDOWS认证进程还是采用SQL Server认证进程取决于该用户连接到系统的网络协议类型。
注意:在SQL Server系统中,除了网络协议Named pipes和TCP/IP,其他的网络通信协议都是非信任连接协议。
(完整版)数据库系统基础教程第八章答案
Section 1Exercise 8.1.1a)CREATE VIEW RichExec ASSELECT * FROM MovieExec WHERE netWorth >= 10000000;b)CREATE VIEW StudioPres (name, address, cert#) ASSELECT , MovieExec.address, MovieExec.cert# FROM MovieExec, Studio WHERE MovieExec.cert# = Studio.presC#;c)CREATE VIEW ExecutiveStar (name, address, gender, birthdate, cert#, netWorth) AS SELECT , star.address, star.gender, star.birthdate, exec.cert#, WorthFROM MovieStar star, MovieExec exec WHERE = ANDstar.address = exec.address;Exercise 8.1.2a)SELECT name from ExecutiveStar WHERE gender = ‘f’;b)SELECT from RichExec, StudioPres where = ;c)SELECT from ExecutiveStar, StudioPresWHERE Worth >= 50000000 ANDStudioPres.cert# = RichExec.cert#;Section 2Exercise 8.2.1The views RichExec and StudioPres are updatable; however, the StudioPres view needs to be created with a subquery.CREATE VIEW StudioPres (name, address, cert#) ASSELECT , MovieExec.address, MovieExec.cert# FROM MovieExecWHERE MovieExec.cert# IN (SELECT presCt# from Studio);Exercise 8.2.2a) Yes, the view is updatable.b)CREATE TRIGGER DisneyComedyInsertINSTEAD OF INSERT ON DisneyComediesREFERENCING NEW ROW AS NewRowFOR EACH ROWINSERT INTO Movies(title, year, length, studioName, genre)VALUES(NewRow.title, NewRow.year, NewYear.length, ‘Disney’, ‘comedy’);c)CREATE TRIGGER DisneyComedyUpdateINSTEAD OF UPDATE ON DisneyComediesREFERENCING NEW ROW AS NewRowFOR EACH ROWUPDATE Movies SET length NewRow.lengthWHERE title = NewRow.title AND year = NEWROW.year ANDstudionName = ‘Disney’ AND genre = ‘comedy’;Exercise 8.2.3a) No, the view is not updatable since it is constructed from two different relations.b)CREATE TRIGGER NewPCInsertINSTEAD OF INSERT ON NewPCREFERENCING NEW ROW AS NewRowFOR EACH ROW(INSERT INTO Product VALUES(NewRow.maker, NewRow.model, ‘pc’))(INSERT INTO PC VALUES(NewRow.model, NewRow.speed, NewRow.ram, NewRow.hd, NewRow.price));c)CREATE TRIGGER NewPCUpdateINSTEAD OF UPDATE ON NewPCREFERENCING NEW ROW AS NewRowFOR EACH ROWUPDATE PC SET price = NewPC.price where model = NewPC.model;d)CREATE TRIGGER NewPCDeleteINSTEAD OF DELETE ON NeePCREFERENCING OLD ROW AS OldRowFOR EACH ROW(DELETE FROM Product WHERE model = OldRow.model)(DELETE FROM PC where model = OldRow.model);Section 3Exercise 8.3.1a)CREATE INDEX NameIndex on Studio(name);b)CREATE INDEX AddressIndex on MovieExec(address);c)CREATE INDEX GenreIndex on Movies(genre, length);Section 4Exercise 8.4.1Exercise 8.4.2Q1 = SELECT * FROM Ships WHERE name = n;Q2 = SELECT * FROM Ships WHERE class = c;Q3 = SELECT * FROM Ships WHERE launched = y;I = InsertsIndexesNone Name Class Launched Name & Name & Class & ThreeSection 5Exercise 8.5.1Updates to movies that involves title or yearUPDATE MovieProd SET title = ‘newTitle’ where title=’oldTitle’ AND year = oldYear; UPDATE MovieProd SET year = newYear where title=’oldYitle’ AND year = oldYear;Update to MovieExec involving cert#DELETE FROM MovieProdWHERE (title, year) IN (SELECT title, yearFROM Movies, MovieExecWHERE cert# = oldCert# AND cert# = producerC#);INSERT INTO MovieProdSELECT title, year, nameFROM Movies, MovieExecWHERE cert# = newCert# AND cert# = producerC#;Exercise 8.5.2Insertions, deletions, and updates to the base tables Product and PC would require a modification of the materialized view.Insertions into Product with type equal to ‘pc’:INSERT INTO NewPCSELECT maker, model, speed, ram, hd, price FROM Product, PC WHEREProduct.model = newModel and Product.model = PC.model;Insertions into PC:INSERT INTO NewPCSELECT maker, ‘newModel’, ‘newSpeed’, ‘newRam’, ‘newHd’, ‘newPrice’FROM Product WHERE model = ‘newModel’;Deletions from Product with type equal to ‘pc’:DELETE FROM NewPC WHERE maker = ‘deletedMaker’ AND model=’deletedModel’; Deletions from PC:DELETE FROM NewPC WHERE model = ‘deletedModel’;Updates to PC:Update NewPC SET speed=PC.speed, ram=PC.ram, hd=PC.hd, price=PC.price FROM PC where model=pc.model;Update to the attribute ‘model’ needs to be treated as a delete and an insert. Updates to Product:Any changes to a Product tuple whose type is ‘pc’ need to be treated as a delete or an insert, or both.Exercise 8.5.3Modifications to the base tables that would require a modification to the materialized view: inserts and deletes from Ships, deletes from class, updates to a Class’ displacement. Deletions from Ship:UPDATE ShipStats SETdisplacement=((displacement * count) –(SELECT displacementFROM ClasssesWHERE class = ‘DeletedShipClass’)) / (count – 1),count = count – 1WHEREcountry = (SELECT country FROM C lasses WHERE class=’DeletedShipClass’); Insertions into Ship:Update ShipStat SETdisplacement=((displacement*count) +(SELECT displacement FROM ClassesWHERE class=’InsertedShipClass’)) / (count + 1),count = count + 1WHEREcountry = (SELECT country FROM Classes WHERE classes=’InsertedShipClass); Deletes from Classes:NumRowsDeleted = SELECT count(*) FROM ships WHERE class = ‘DeletedClass’; UPDATE ShipStats SETdisplacement = (displacement * count) - (DeletedClassDisplacement *NumRowsDeleted)) / (count – NumRowsDeleted),count = count – NumRowsDeletedWHERE country = ‘DeletedClassCountry’;Update to a Class’ displacement:N = SELECT count(*) FROM Ships where class = ‘UpdatedClass’;UPDATE ShipsStat SETdisplacement = ((displacement * count) + ((oldDisplacement – newDisplacement) * N))/countWHEREc ountry = ‘UpdatedClassCountry’;Exercise 8.5.4Queries that can be rewritten with the materialized view:Names of stars of movies produced by a certain producerSELECT starNameFROM StarsIn, Movies, MovieExecWHERE movieTitle = title AND movieYear = year AND producerC# = cert# AND name = ‘Max Bialystock’;Movies produced by a certain producerSELECT title, yearFROM Movies, MovieExecWhere produce rC# = cert# AND name = ‘George Lucas’;Names of producers that a certain star has worked withSELECT nameFROM Movies, MovieExec, StarsInWhere producerC#=cert# AND title=movieTitle AND year=movieYear AND starName=’Carrie Fisher’;The number of movies produced by given producerSELECT count(*)FROM Movies, MovieExecWHER E producerC#=cert# AND name = ‘George Lucas‘;Names of producers who also starred in their own moviesSELECT nameFROM Movies, StarsIn, MovieExecWHERE producerC#=cert# AND movieTitle = title AND movieYear = year AND = starName;The number of stars that have starred in movies produced by a certain producer SELECT count(DISTINCT starName)FROM Movies, StarsIn, MovieExecWHERE producerC#=cert# AND movieTitle = title AND movieYear = year AND n ame ‘George Lucas’;The number of movies produced by each producerSELECT name, count(*)FROM Movies, MovieExecWHERE producerC#=cert# GROUP BY name。
(完整版)数据库系统基础教程第八章答案
Section 1Exercise 8.1.1a)CREATE VIEW RichExec ASSELECT * FROM MovieExec WHERE netWorth >= 10000000;b)CREATE VIEW StudioPres (name, address, cert#) ASSELECT , MovieExec.address, MovieExec.cert# FROM MovieExec, Studio WHERE MovieExec.cert# = Studio.presC#;c)CREATE VIEW ExecutiveStar (name, address, gender, birthdate, cert#, netWorth) AS SELECT , star.address, star.gender, star.birthdate, exec.cert#, WorthFROM MovieStar star, MovieExec exec WHERE = ANDstar.address = exec.address;Exercise 8.1.2a)SELECT name from ExecutiveStar WHERE gender = ‘f’;b)SELECT from RichExec, StudioPres where = ; c)SELECT from ExecutiveStar, StudioPresWHERE Worth >= 50000000 ANDStudioPres.cert# = RichExec.cert#;Section 2Exercise 8.2.1The views RichExec and StudioPres are updatable; however, the StudioPres view needs to be created with a subquery.CREATE VIEW StudioPres (name, address, cert#) ASSELECT , MovieExec.address, MovieExec.cert# FROM MovieExec WHERE MovieExec.cert# IN (SELECT presCt# from Studio);Exercise 8.2.2a) Yes, the view is updatable.b)CREATE TRIGGER DisneyComedyInsertINSTEAD OF INSERT ON DisneyComediesREFERENCING NEW ROW AS NewRowFOR EACH ROWINSERT INTO Movies(title, year, length, studioName, genre)VALUES(NewRow.title, NewRow.year, NewYear.length, ‘Disney’, ‘comedy’);c)CREATE TRIGGER DisneyComedyUpdateINSTEAD OF UPDATE ON DisneyComediesREFERENCING NEW ROW AS NewRowFOR EACH ROWUPDATE Movies SET length NewRow.lengthWHERE title = NewRow.title AND year = NEWROW.year ANDstudionName = ‘Disney’ AND genre = ‘comedy’;Exercise 8.2.3a) No, the view is not updatable since it is constructed from two different relations.b)CREATE TRIGGER NewPCInsertINSTEAD OF INSERT ON NewPCREFERENCING NEW ROW AS NewRowFOR EACH ROW(INSERT INTO Product VALUES(NewRow.maker, NewRow.model, ‘pc’))(INSERT INTO PC VALUES(NewRow.model, NewRow.speed, NewRow.ram, NewRow.hd, NewRow.price));c)CREATE TRIGGER NewPCUpdateINSTEAD OF UPDATE ON NewPCREFERENCING NEW ROW AS NewRowFOR EACH ROWUPDATE PC SET price = NewPC.price where model = NewPC.model;d)CREATE TRIGGER NewPCDeleteINSTEAD OF DELETE ON NeePCREFERENCING OLD ROW AS OldRowFOR EACH ROW(DELETE FROM Product WHERE model = OldRow.model)(DELETE FROM PC where model = OldRow.model);Section 3Exercise 8.3.1a)CREATE INDEX NameIndex on Studio(name);b)CREATE INDEX AddressIndex on MovieExec(address);c)CREATE INDEX GenreIndex on Movies(genre, length);Section 4Exercise 8.4.1Action No Index Star Index Movie Index Both Indexes Q110041004Q210010044I2446 Average 2 + 98p1 + 98p2 4 + 96 p2 4 + 96 p1 6 – 2 p1 – 2 p2 Exercise 8.4.2Q1 = SELECT * FROM Ships WHERE name = n;Q2 = SELECT * FROM Ships WHERE class = c;Q3 = SELECT * FROM Ships WHERE launched = y;I = InsertsIndexes Actions None Name Class Launched Name &ClassName &LaunchedClass &LaunchedThreeIndexesQ1502505022502 Q21121212 2 Q35050502650262626 I24446668Average 2 +48p1 -p2 +48p34 +46 p3- 2 p1- 3 p24 +46p1 -2p2 +46p34 + 46p1- 3p2 +22p36 - 4p1- 4p2 +44p36 - 4p1 -5p2 + 20p36 - 44p1 -4p2 + 20p38 - 6p1 -6p2 + 18p3The best choice of indexes (name and launched) has an average cost of 6 - 4p1 - 5p2 + 20p3 per operation.Section 5Exercise 8.5.1Updates to movies that involves title or yearUPDATE MovieProd SET title = ‘newTitle’ where title=’oldTitle’ AND year = oldYear; UPDATE MovieProd SET year = newYear where title=’oldYitle’ AND year = oldYear; Update to MovieExec involving cert#DELETE FROM MovieProdWHERE (title, year) IN (SELECT title, yearFROM Movies, MovieExecWHERE cert# = oldCert# AND cert# = producerC#);INSERT INTO MovieProdSELECT title, year, nameFROM Movies, MovieExecWHERE cert# = newCert# AND cert# = producerC#;Exercise 8.5.2Insertions, deletions, and updates to the base tables Product and PC would require a modification of the materialized view.Insertions into Product with type equal to ‘pc’:INSERT INTO NewPCSELECT maker, model, speed, ram, hd, price FROM Product, PC WHEREProduct.model = newModel and Product.model = PC.model;Insertions into PC:INSERT INTO NewPCSELECT maker, ‘newModel’, ‘newSpeed’, ‘newRam’, ‘newHd’, ‘newPrice’FROM Product WHERE model = ‘newModel’;Deletions from Product with type equal to ‘pc’:DELETE FROM NewPC WHERE maker = ‘deletedMaker’ ANDmodel=’deletedModel’;Deletions from PC:DELETE FROM NewPC WHERE model = ‘deletedModel’;Updates to PC:Update NewPC SET speed=PC.speed, ram=PC.ram, hd=PC.hd, price=PC.price FROM PC where model=pc.model;Update to the attribute ‘model’ needs to be treated as a delete and an insert. Updates to Product:Any changes to a Product tuple whose type is ‘pc’ need to be treated as a delete or an insert, or both.Exercise 8.5.3Modifications to the base tables that would require a modification to the materialized view: inserts and deletes from Ships, deletes from class, updates to a Class’ displacement. Deletions from Ship:UPDATE ShipStats SETdisplacement=((displacement * count) –(SELECT displacementFROM ClasssesWHERE class = ‘DeletedShipClass’)) / (count – 1),count = count – 1WHEREcountry = (SELECT country FROM Classes WHERE class=’DeletedShipClass’); Insertions into Ship:Update ShipStat SETdisplacement=((displacement*count) +(SELECT displacement FROM ClassesWHERE class=’InsertedShipClass’)) / (count + 1),count = count + 1WHEREcountry = (SELECT country FROM Classes WHERE classes=’InsertedShipClass); Deletes from Classes:NumRowsDeleted = SELECT count(*) FROM ships WHERE class = ‘DeletedClass’; UPDATE ShipStats SETdisplacement = (displacement * count) - (DeletedClassDisplacement *NumRowsDeleted)) / (count – NumRowsDeleted),count = count – NumRowsDeletedWHERE country = ‘DeletedClassCountry’;Update to a Class’ displacement:N = SELECT count(*) FROM Ships where class = ‘UpdatedClass’;UPDATE ShipsStat SETdisplacement = ((displacement * count) + ((oldDisplacement – newDisplacement) * N))/countWHEREcountry = ‘UpdatedClassCountry’;Exercise 8.5.4Queries that can be rewritten with the materialized view:Names of stars of movies produced by a certain producerSELECT starNameFROM StarsIn, Movies, MovieExecWHERE movieTitle = title AND movieYear = year AND producerC# = cert# AND name = ‘Max Bialystock’;Movies produced by a certain producerSELECT title, yearFROM Movies, MovieExecWhere producerC# = cert# AND name = ‘George Lucas’;Names of producers that a certain star has worked withSELECT nameFROM Movies, MovieExec, StarsInWhere producerC#=cert# AND title=movieTitle AND year=movieYear AND starName=’Carrie Fisher’;The number of movies produced by given producerSELECT count(*)FROM Movies, MovieExecWHERE producerC#=cert# AND name = ‘George Lucas‘;Names of producers who also starred in their own moviesSELECT nameFROM Movies, StarsIn, MovieExecWHERE producerC#=cert# AND movieTitle = title AND movieYear = year AND = starName;The number of stars that have starred in movies produced by a certain producer SELECT count(DISTINCT starName)FROM Movies, StarsIn, MovieExecWHERE producerC#=cert# AND movieTitle = title AND movieYear = year AND name ‘George Lucas’;The number of movies produced by each producerSELECT name, count(*)FROM Movies, MovieExecWHERE producerC#=cert# GROUP BY name。
数据库原理与应用系列第八章习题(含答案)
第八章习题(答案)班级:学号: 姓名:1.填空题(1)SQL Server 有两种安全认证模式,即___WINDOWS_______________安全认证模式和______混合______安全认证模式。
(2)SQL SERVER安装好以后,只有2个已经创建的用户:___SA_______和BULTIN/administrators,它们都是超级用户,对数据库拥有一切权限。
(3)数据库的完整性是指数据的___正确性___和___相容性____。
(4)按数据库状态,数据转储分为动态转储和静态转储。
(5)按数据转储方式,数据转储分为海量转储和增量转储。
2.单选题(1)日志文件用于记录( D )。
A、程序运行过程B、数据操作C、程序运行结果D、对数据的更新操作(2)SQL的COMMIT语句的主要作用是( C )。
A、终止程序B、中断程序C、事务提交D、事务回退(3)SQL的ROLLBACK语句的主要作用是( D )。
A、终止程序B、中断程序C、事务提交D、事务回退(4)在数据库系统中,对存取权限的定义称为(B)。
A、命令B、授权C、定义D、审计(5)设有两个事务T1,T2,其并发操作如下表所示,下面评价正确的是(C )。
A、该操作不存在问题B、该操作丢失修改C、该操作不能重复读D、该操作读“脏”数据(6)设有两个事务T1,T2,其并发操作如下表所示,下面评价正确的是(B )。
A、该操作不存在问题B、该操作丢失修改C、该操作不能重复读D、该操作读“脏”数据(7)A、该操作不存在问题B、该操作丢失修改C、该操作不能重复读D、该操作读“脏”数据(8)若事务T对数据对象A加上S锁,则( C )A、事务T可以读A和修改A,其他事务只能再对A加S锁,而不能加X锁B、事务T可以读A但不能修改A,其他事务能对A加S锁和X锁C、事务T可以读A但不能修改A,其他事务只能再对A加S锁,而不能加X锁D、事务T可以读A和修改A,其他事务能对A加S锁和X锁(9)若事务T对数据对象A加上X锁,则( C )A、事务T可以读A和修改A,其他事务不能对A加X锁B、事务T可以修改A,其他事务不能对A加X锁C、事务T可以读A和修改A,其他事务都不能再对A加任何类型的锁D、事务T修改A,其他事务都不能再对A加任何类型的锁(10)数据库中的封锁机制是( C )的主要方法。
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
4.设有函数依赖集F={AB→CE,A→C,GP→B,EP→A,CDE→P,HB→P,D→HG,ABC →PG},计算属性集D关于F的闭包D+。
解:令X={D},X(0)=D。
在F中找出左边是D子集的函数依赖,其结果是:D→HG,∴X(1)=X(0)HG=DGH,显然有X(1)≠X(0)。
在F中找出左边是DGH子集的函数依赖,未找到,则X(2)=DGH。
由于X(2)=X (1),则D+=DGH
5求与F={A→C,C→A,B→AC,D→AC,BD→A}等价的最小相关性集合。
F->{A->C,C->A,B->C,D->C}
9.设有关系模式R(U,F),其中:
U={A,B,C,D,E},F={A→D,E→D,D→B,BC→D,DC→A}
⑴求出R的候选关键字。
⑵判断p={AB,AE,CE,BCD,AC}是否为无损连接分解?
解:
⑴(CE)+=ABCDE,则CE→U,而C+=C,E+=DE=BDE,根据候选关键字定义,CE 是R的候选关键字。
⑵p的无损连接性判断表如下图所示,由此判断不具有无损连接性。
Ri A B C D E
AB a1 a2
AE a1 a5
CE a3 a5
BCD a2 a3 a4
AC a1 a3
11、设有关系框架R(A,B,C,D,E,F)及其上的函数相关性集合F={A B,C F,E A,CE D}:
(1)求出R的所有候选关键字。
(2)将R无损连接分解到BCNF.
主属性CE
CE+=CEFABD
候选关键字CE
R1={A,B}
R2={C,F}
R3={E,A}
R4={C,E,D}。