数据库系统原理课后答案 第五章
2020年智慧树知道网课《数据库系统原理》课后章节测试满分答案
绪论单元测试
1
【单选题】(2分)
因为提出关系模型而获得图灵奖的是
A.
E.F.Codd
B.
MichaelStonebraker
C.
CharlesW.Bachman
D.
JimGray
第一章测试
1
【单选题】(2分)
在数据模型中,对数据静态特性描述的是()
A.
数据模式
B.
数据操作
C.
数据结构
D.
数据完整性
2
【单选题】(2分)
目前最流行的数据模型是()
A.
关系模型
B.
层次模型
C.
网状模型
D.
面向对象模型
3
【单选题】(2分)
下面定义数据库中各种数据对象实例上允许的操作和操作规则的是()
A.
数据操作
B.
数据完整性
C.
ABC都不正确
D.
数据结构
4
【单选题】(2分)
下面可以保证数据逻辑独立性的是()
A.
外模式
B.
外模式-模式映像
C.
模式
D.
模式-内模式映像
5
【单选题】(2分)
数据库管理系统的简称是()
A.
DB
B.
DBM
C.
DBMS
D.
DBS
6
【判断题】(2分)
关系的每个属性必须取原子值()
A.
对
B.
错
7
【多选题】(2分)
数据模型的组成要素包括()
A.
数据对象
B.
数据操纵
C.
数据完整性约束
D.
数据结构
第二章测试
1。
04735数据库系统原理(2021版)课后习题参考答案
04735数据库系统原理(2021版)课后习题参考答案答案仅供参考第一章数据库系统概述选择题B、B、A简答题1.请简述数据,数据库,数据库管理系统,数据库系统的概念。
P27数据是描绘事物的记录符号,是指用物理符号记录下来的,可以鉴别的信息。
数据库即存储数据的仓库,严格意义上是指长期存储在计算机中的有组织的、可共享的数据集合。
数据库管理系统是专门用于建立和管理数据库的一套软件,介于应用程序和操作系统之间。
数据库系统是指在计算机中引入数据库技术之后的系统,包括数据库、数据库管理系统及相关实用工具、应用程序、数据库管理员和用户。
2.请简述早数据库管理技术中,与人工管理、文件系统相比,数据库系统的优点。
数据共享性高数据冗余小易于保证数据一致性数据独立性高可以施行统一管理与控制减少了应用程序开发与维护的工作量3.请简述数据库系统的三级形式和两层映像的含义。
P31答:数据库的三级形式是指数据库系统是由形式、外形式和内形式三级工程的,对应了数据的三级抽象。
两层映像是指三级形式之间的映像关系,即外形式/形式映像和形式/内形式映像。
4.请简述关系模型与网状模型、层次模型的区别。
P35使用二维表构造表示实体及实体间的联络建立在严格的数学概念的根底上概念单一,统一用关系表示实体和实体之间的联络,数据构造简单明晰,用户易懂易用存取途径对用户透明,具有更高的数据独立性、更好的平安保密性。
第二章关系数据库选择题C、C、D简答题1.请简述关系数据库的根本特征。
P48答:关系数据库的根本特征是使用关系数据模型组织数据。
2.请简述什么是参照完好性约束。
P55答:参照完好性约束是指:假设属性或属性组F是根本关系R的外码,与根本关系S的主码K相对应,那么对于R中每个元组在F上的取值只允许有两种可能,要么是空值,要么与S中某个元组的主码值对应。
3.请简述关系标准化过程。
答:对于存在数据冗余、插入异常、删除异常问题的关系形式,应采取将一个关系形式分解为多个关系形式的方法进展处理。
数据库系统概论第五版课后习题答案
第1章绪论1 .试述数据、数据库、数据库系统、数据库管理系统的概念。
答:( l )数据( Data ) :描述事物的符号记录称为数据。
数据的种类有数字、文字、图形、图像、声音、正文等。
数据与其语义就是不可分的。
解析在现代计算机系统中数据的概念就是广义的。
早期的计算机系统主要用于科学计算,处理的数据就是整数、实数、浮点数等传统数学中的数据。
现代计算机能存储与处理的对象十分广泛,表示这些对象的数据也越来越复杂。
数据与其语义就是不可分的。
500这个数字可以表示一件物品的价格就是 500元,也可以表示一个学术会议参加的人数有 500人,还可以表示一袋奶粉重 500克。
( 2 )数据库( DataBase ,简称 DB ) :数据库就是长期储存在计算机内的、有组织的、可共享的数据集合。
数据库中的数据按一定的数据模型组织、描述与储存,具有较小的冗余度、较高的数据独立性与易扩展性,并可为各种用户共享。
( 3 )数据库系统( DataBas。
Sytem ,简称 DBS ) :数据库系统就是指在计算机系统中引入数据库后的系统构成,一般由数据库、数据库管理系统(及其开发工具)、应用系统、数据库管理员构成。
解析数据库系统与数据库就是两个概念。
数据库系统就是一个人一机系统,数据库就是数据库系统的一个组成部分。
但就是在日常工作中人们常常把数据库系统简称为数据库。
希望读者能够从人们讲话或文章的上下文中区分“数据库系统”与“数据库”,不要引起混淆。
( 4 )数据库管理系统( DataBase Management sytem ,简称 DBMs ) :数据库管理系统就是位于用户与操作系统之间的一层数据管理软件,用于科学地组织与存储数据、高效地获取与维护数据。
DBMS的主要功能包括数据定义功能、数据操纵功能、数据库的运行管理功能、数据库的建立与维护功能。
解析 DBMS就是一个大型的复杂的软件系统,就是计算机中的基础软件。
目前,专门研制 DBMS的厂商及其研制的 DBMS产品很多。
数据库系统原理04735课后习题参考答案
数据库系统原理课后习题第一章. 数据库系统基本概念1.1.名词解释DB——DB是长期存储在计算机内、有组织的、统一管理的相关数据的集合。
DB能为各种用户共享,具有较小冗余度、数据间联系紧密而又有较高的数据独立性等特点。
DBMS——是位于用户与操作系统之间的一层数据管理软件,它为用户或应用程序提供访问DB的方法,包括DB的建立、查询、更新及各种数据控制。
DBS——是实现有组织地、动态地存储大量关联数据、方便多用户访问的计算机硬件、软件和数据资源组成的系统,即它是采用数据库技术的计算机系统。
联系——是实体间的相互关系。
联系的元数——与一个联系有关的实体集个数。
1:1联系——如果实体集E1中每个实体至多和实体集E2中一个实体有联系,反之亦然,那么实体集E1和E2的联系称为“一对一联系”,记为“1:1”。
1:N联系——如果实体集E1中的每个实体可以与实体集E2中的任意个(0个或多个)实体有联系,而E2中的每个实体至多和E1中的一个实体有联系,那么称E1对E2的联系是一对多联系,记作:“1:N ”。
M:N联系——如果实体集E1中的每个实体可以与实体集E2中的任意个(0个或多个)实体有联系,反之亦然,那么称E1和E2的联系是“多对多联系”,记作“M:N”。
数据模型——在数据库技术中,我们用数据模型的概念描述数据库的结构和语义,对现实世界的数据进行抽象。
根据数据抽象级别定义了四种模型:概念数据模型、逻辑数据模型、外部数据模型和内部数据模型。
概念模型——表达用户需求观点的数据全局逻辑结构的模型。
逻辑模型——表达计算机实现观点的DB全局逻辑结构的模型。
主要有层次、网状、关系模型等三种。
外部模型——表达用户使用观点的DB局部逻辑结构的模型。
内部模型——表达DB物理结构的模型。
层次模型——用树型(层次)结构表示实体类型及实体间联系的数据模型。
网状模型——用有向图结构表示实体类型及实体间联系的数据模型。
关系模型——是由若干个关系模式组成的集合。
数据库系统基础教程课后答案第五章
Exercise 5.1.1 As a set:Average = 2.37 As a bag:Average = 2.48 Exercise 5.1.2 As a set:Average = 218 As a bag:Average = 215 Exercise 5.1.3a As a set:As a bag:Exercise 5.1.3bπbore(Ships Classes)Exercise 5.1.4aFor bags:On the left-hand side:Given bags R and S where a tuple t appears n and m times respectively, the union of bags R and S will have tuple t appear n + m times. The further union of bag T with the tuple t appearing o times will have tuple t appear n + m + o times in the final result.On the right-hand side:Given bags S and T where a tuple t appears m and o times respectively, the union of bags R and S will have tuple t appear m + o times. The further union of bag R with the tuple t appearing n times will have tuple t appear m + o + n times in the final result.For sets:This is a similar case when dealing with bags except the tuple t can only appear at most once in each set. The tuple t only appears in the result if all the sets have the tuple t. Otherwise, the tuple t will not appear in the result. Since we cannot have duplicates, the result only has at most one copy of the tuple t.Exercise 5.1.4bFor bags:On the left-hand side:Given bags R and S where a tuple t appears n and m times respectively, the intersectionof bags R and S will have tuple t appear min( n, m ) times. The further intersection of bag T with the tuple t appearing o times will produce tuple t min( o, min( n, m ) ) times in the final result.On the right-hand side:Given bags S and T where a tuple t appears m and o times respectively, the intersection of bags R and S will have tuple t appear min( m, o ) times. The further intersection of bag R with the tuple t appearing n times will produce tuple t min( n, min( m, o ) ) times in thefinal result.The intersection of bags R,S and T will yield a result where tuple t appears min( n,m,o ) times. For sets:This is a similar case when dealing with bags except the tuple t can only appear at most once in each set. The tuple t only appears in the result if all the sets have the tuple t. Otherwise, the tuple t will not appear in the result.Exercise 5.1.4cFor bags:On the left-hand side:Given that tuple r in R, which appears m times, can successfully join with tuple s in S,which appears n times, we expect the result to contain mn copies. Also given that tuple tin T, which appears o times, can successfully join with the joined tuples of r and s, weexpect the final result to have mno copies.On the right-hand side:Given that tuple s in S, which appears n times, can successfully join with tuple t in T,which appears o times, we expect the result to contain no copies. Also given that tuple rin R, which appears m times, can successfully join with the joined tuples of s and t, weexpect the final result to have nom copies.The order in which we perform the natural join does not matter for bags.For sets:This is a similar case when dealing with bags except the joined tuples can only appear at most once in each result. If there are tuples r,s,t in relations R,S,T that can successfully join, then the result will contain a tuple with the schema of their joined attributes.Exercise 5.1.4dFor bags:Suppose a tuple t occurs n and m times in bags R and S respectively. In the union of these two bags R ⋃ S, tuple t would appear n + m times. Likewise, in the union of these two bags S ⋃ R, tuple t would appear m + n times. Both sides of the relation yield the same result.For sets:A tuple t can only appear at most one time. Tuple t might appear each in sets R and S one or zero times. The combinations of number of occurrences for tuple t in R and S respectively are (0,0), (0,1), (1,0), and (1,1). Only when tuple t appears in both sets R and S will the union R ⋃ S have the tuple t. The same reasoning holds when we take the union S ⋃ R.Therefore the commutative law for union holds.Exercise 5.1.4eFor bags:Suppose a tuple t occurs n and m times in bags R and S respectively. In the intersection of these two bags R ∩ S, tuple t would appear min( n,m ) times. Likewise in the intersection of these two bags S ∩ R, tuple t would appear min( m,n ) times. Both sides of the relation yield the same result.For sets:A tuple t can only appear at most one time. Tuple t might appear each in sets R and S one or zero times. The combinations of number of occurrences for tuple t in R and S respectively are (0,0), (0,1), (1,0), and (1,1). Only when tuple t appears in at least one of the sets R and S will the intersection R ∩ S have the tuple t. The same reasoning holds when we take the intersection S ∩ R.Therefore the commutative law for intersection holds.Exercise 5.1.4fFor bags:Suppose a tuple t occurs n times in bag R and tuple u occurs m times in bag S. Suppose also that the two tuples t,u can successfully join. Then in the natural join of these two bags R S, the joined tuple would appear nm times. Likewise in the natural join of these two bags S R, the joined tuple would appear mn times. Both sides of the relation yield the same result.For sets:An arbitrary tuple t can only appear at most one time in any set. Tuples u,v might appear respectively in sets R and S one or zero times. The combinations of number of occurrences for tuples u,v in R and S respectively are (0,0), (0,1), (1,0), and (1,1). Only when tuple u exists in Rand tuple v exists in S will the natural join R S have the joined tuple. The same reasoning holds when we take the natural join S R.Therefore the commutative law for natural join holds.Exercise 5.1.4gFor bags:Suppose tuple t appears m times in R and n times in S. If we take the union of R and S first, we will get a relation where tuple t appears m + n times. Taking the projection of a list of attributes L will yield a resulting relation where the projected attributes from tuple t appear m + n times. If we take the projection of the attributes in list L first, then the projected attributes from tuple t would appear m times from R and n times from S. The union of these resulting relations would have the projected attributes of tuple t appear m + n times.For sets:An arbitrary tuple t can only appear at most one time in any set. Tuple t might appear in sets R and S one or zero times. The combinations of number of occurrences for tuple t in R and S respectively are (0,0), (0,1), (1,0), and (1,1). Only when tuple t exists in R or S (or both R and S) will the projected attributes of tuple t appear in the result.Therefore the law holds.Exercise 5.1.4hFor bags:Suppose tuple t appears u times in R, v times in S and w times in T. On the left hand side, the intersection of S and T would produce a result where tuple t would appear min(v , w) times. With the addition of the union of R, the overall result would have u + min(v , w) copies of tuple t. On the right hand side, we would get a result of min(u + v, u + w) copies of tuple t. The expressions on both the left and right sides are equivalent.For sets:An arbitrary tuple t can only appear at most one time in any set. Tuple t might appear in sets R,S and T one or zero times. The combinations of number of occurrences for tuple t in R, S and T respectively are (0,0,0), (0,0,1), (0,1,0), (0,1,1), (1,0,0), (1,0,1), (1,1,0) and (1,1,1). Only when tuple t appears in R or in both S and T will the result have tuple t.Therefore the distributive law of union over intersection holds.Exercise 5.1.4iSuppose that in relation R, u tuples satisfy condition C and v tuples satisfy condition D. Suppose also that w tuples satisfy both conditions C and D where w≤ min(v , w). Then the left hand side will return those w tuples. On the right hand side, σC(R) produces u tuples and σD(R) produces v tuples. However, we know the intersection will produce the same w tuples in the result.When considering bags and sets, the only difference is bags allow duplicate tuples while sets only allow one copy of the tuple. The example above applies to both cases.Therefore the law holds.Exercise 5.1.5aFor sets, an arbitrary tuple t appears on the left hand side if it appears in both R,S and not in T. The same is true for the right hand side.As an example for bags, suppose that tuple t appears one time each in both R,T and two times in S. The result of the left hand side would have zero copies of tuple t while the right hand side would have one copy of tuple t.Therefore the law holds for sets but not for bags.Exercise 5.1.5bFor sets, an arbitrary tuple t appears on the left hand side if it appears in R and either S or T. This is equivalent to saying tuple t only appears when it is in at least R and S or in R and T. The equivalence is exactly the right side’s expression.As an example for bags, suppose that tuple t appears one time in R and two times each in S and T. Then the left hand side would have one copy of tuple t in the result while the right hand side would have two copies of tuple t.Therefore the law holds for sets but not for bags.Exercise 5.1.5cFor sets, an arbitrary tuple t appears on the left hand side if it satisfies condition C, condition Dor both condition C and D. On the right hand side, σC(R) selects those tuples that satisfy condition C while σD(R) selects those tuples that satisfy condition D. However, the union operator will eliminate duplicate tuples, namely those tuples that satisfy both condition C and D. Thus we are ensured that both sides are equivalent.As an example for bags, we only need to look at the union operator. If there are indeed tuples that satisfy both conditions C and D, then the right hand side will contain duplicate copies of those tuples. The left hand side, however, will only have one copy for each tuple of the original set of tuples.Exercise 5.2.1bExercise 5.2.1cExercise 5.2.1dExercise 5.2.1fExercise 5.2.1gExercise 5.2.1hExercise 5.2.1iExercise 5.2.1jExercise 5.2.1kExercise 5.2.1lExercise 5.2.1mExercise 5.2.1nExercise 5.2.2aApplying the δ operator on a relation with no duplicates will yield the same relation. Thus δ is idempotent.Exercise 5.2.2bThe result of πL is a relation over the list of attributes L. Performing the projection again will return the same relation because the relation only contains the list of attributes L. Thus πL is idempotent.Exercise 5.2.2cThe result of σC is a relation where condition C is satisfied by every tuple. Performing the selection again will return the same relation because the relation only contains tuples that satisfy the condition C. Thus σC is idempotent.Exercise 5.2.2dThe result of γL is a relation whose schema consists of the grouping attributes and the aggregated attributes. If we perform the same grouping operation, there is no guarantee that the expression would make sense. The grouping attributes will still appear in the new result. However, the aggregated attributes may or may not appear correctly. If the aggregated attribute is given a different name than the original attribute, then performing γL would not make sense because it contains an aggregation for an attribute name that does not exist. In this case, the resultingrelation would, according to the definition, only contain the grouping attributes. Thus, γL is not idempotent.Exercise 5.2.2eThe result of τ is a sorted list of tuples based on some attributes L. If L is not the entire schema of relation R, then there are attributes that are not sorted on. If in relation R there are two tuples that agree in all attributes L and disagree in some of the remaining attributes not in L, then it is arbitrary as to which order these two tuples appear in the result. Thus, performing the operation τ multiple times can yield a different relation where these two tuples are swapped. Thus, τ is not idempotent.Exercise 5.2.3If we only consider sets, then it is possible. We can take πA(R) and do a product with itself. From this product, we take the tuples where the two columns are equal to each other.If we consider bags as well, then it is not possible. Take the case where we have the two tuples (1,0) and (1,0). We wish to produce a relation that contains tuples (1,1) and (1,1). If we use the classical operations of relational algebra, we can either get a result where there are no tuples or four copies of the tuple (1,1). It is not possible to get the desired relation because no operation can distinguish between the original tuples and the duplicated tuples. Thus it is not possible to get the relation with the two tuples (1,1) and (1,1).Exercise 5.3.1a)Answer(model) ← PC(model,speed,_,_,_) AND speed ≥ 3.00b)Answer(maker) ← Laptop(model,_,_,hd,_,_) AND Product(maker,model,_) AND hd ≥100c)Answer(model,price) ← PC(model,_,_,_,price) AND Product(maker,model,_) ANDmaker=’B’Answer(model,price) ← Laptop(mode l,_,_,_,_,price) AND Product(maker,model,_)AND maker=’B’Answer(model,price) ← Printer(model,_,_,price) AND Product(maker,model,_) ANDmaker=’B’d)Answer(model) ← Printer(model,color,type,_) AND color=’true’ AND type=’laser’e)PCMaker(maker) ← Product(maker,_,type) AND type=’pc’LaptopMaker(maker) ← Product(maker,_,type) AND type=’laptop’Answer(maker) ← LaptopMaker(maker) AND NOT PCMaker(maker)f)Answer(hd) ← PC(model1,_,_,hd,_) AND PC(model2,_,_,hd,_) AND model1 <>model2g)Answer(model1,model2) ← PC(model1,speed, ram,_,_) ANDPC(model2,_speed,ram,_,_) AND model1 < model2h)FastComputer(model) ← PC(model,speed,_,_,_) AND speed ≥ 2.80FastComputer(model) ← Laptop(model,speed,_,_,_,_) AND speed ≥ 2.80Answer(maker) ← Product(maker,model1,_) AND Product(maker,mod el2,_) ANDFastComputer(model1) AND FastComputer(model2) AND model1 <> model2i)Computers(model,speed) ← PC(model,speed,_,_,_)Computers(model,speed) ← Laptop(model,speed,_,_,_,_)SlowComputers(model) ← Computers(model,speed) AND Computers(model1,speed1)AND speed < speed1FastestComputers(model) ← Computers(model,_) AND NOT SlowComputers(model)Answer(maker) ← Fast estComputers(model) AND Product(maker,model,_)j)PCs(maker,speed) ← PC(model,speed,_,_,_) AND Product(maker,model,_) Answer(maker) ← PCs(maker,spe ed) AND PCs(maker,speed1) AND PCs(maker,speed2) AND speed <> speed1 AND speed <> speed2 AND speed1 <> speed2k)PCs(maker,model) ← Product(maker,model,type) AND type=’pc’Answer(maker) ← PCs(maker,model) AND PCs(maker,model1) ANDPCs(maker,model2) AND PCs(maker,model3) AND model <> model1 AND model <>model2 AND model1 <> model2 AND (model3 = model OR model3 = model1 ORmodel3 = model2)Exercise 5.3.2a)Answer(class,country) ← Classes(class,_,country,_,bore,_) AND bore ≥ 16b)Answer(name) ← Ships(name,_,launch ed) AND launched < 1921c)Answer(ship) ← Outcomes(ship,battle,result) AND battle=’Denmark Strait’ AND result= ‘sunk’d)Answer(name) ← Classes(class,_,_,_,_,displacement) AND Ships(name,class,launched)AND displacement > 35000 AND launched > 1921e)Answer(nam e,displacement,numGuns) ← Classes(class,_,_,numGuns,_,displacement)AND Ships(name,class,_) AND Outcomes (ship,battle,_) AND battle=’Guadalcanal’AND ship=namef)Answer(name) ← Ships(name,_,_)Answer(name) ← Outcomes(name,_,_) AND NOT Answer(name)g)MoreThan One(class) ← Ships(name,class,_) AND Ships(name1,class,_) AND name <>name1Answer(class) ← Classes(class,_,_,_,_,_) AND NOT MoreThanOne(class)h)Battleship(country) ← Classes(_,type,country,_,_,_) AND type=’bb’Battlecruiser(country) ← Classes(_,type,country,_,_,_) AND type=’bc’Answer(country) ← Battleship(country) AND Battlecruiser(country)i)Results(ship,result,date) ← Battles(name,date) AND Outcomes(ship,battle,result) ANDbattle=nameAnswer(ship) ← Results(ship,result,date) AND Results(ship,_,date1) ANDresult=’damaged’ AND date < date1Exercise 5.3.3A nswer(x,y) ← R(x,y) AND z = zExercise 5.4.1aAnswer(a,b,c) ← R(a,b,c)Answer(a,b,c) ← S(a,b,c)Exercise 5.4.1bAnswer(a,b,c) ← R(a,b,c) AND S(a,b,c)Exercise 5.4.1cAnswer(a,b,c) ← R(a,b,c) AND NOT S(a,b,c)Exercise 5.4.1dUnion(a,b,c) ← R(a,b,c)Union(a,b,c) ← S(a,b,c)Answer(a,b,c) ← Union(a,b,c) AND NOT T(a,b,c)Exercise 5.4.1eJ(a,b,c) ← R(a,b,c) AND NOT S(a,b,c)K(a,b,c) ← R(,a,b,c) AND NOT T(a,b,c)Answer(a,b,c) ← J(a,b,c) AND K(a,b,c)Exercise 5.4.1fAnswer(a,b) ← R(a,b,_)Exercise 5.4.1gJ(a,b) ← R(a,b,_)K(a,b) ← S(_,a,b)Answer(a,b) ← J(a,b) AND K(a,b)Exercise 5.4.2aAnswer(x,y,z) ← R(x,y,z) AND x = yExercise 5.4.2bAnswer(x,y,z) ← R(x,y,z) AND x < y AND y < z Exercise 5.4.2cAnswer(x,y,z) ← R(x,y,z) AND x < yAnswer(x,y,z) ← R(x,y,z) AND y < zExercise 5.4.2dChange: NOT(x < y OR x > y)To: x ≥ y AND x ≤ yThe above simplifies to x = yAnswer(x,y,z) ← R(x,y,z) AND x = yExercise 5.4.2eChange: NOT((x < y OR x > y) AND y < z)NOT(x < y OR x > y) OR y ≥ z(x ≥ y AND x ≤ y) OR y ≥ zTo: x = y OR y ≥ zAnswer(x,y,z) ← R(x,y,z) AND x = yAnswer(x,y,z) ← R(x,y,z) AND y ≥ zExercise 5.4.2fChange: NOT((x < y OR x < z) AND y < z)NOT(x < y OR x < z) OR y ≥ z To: (x ≥ y AND x ≥ z) OR y ≥ zAnswer(x,y,z) ← R(x,y,z) AND x ≥ y AND x ≥ zAnswer(x,y,z) ← R(x,y,z) AND y ≥zExercise 5.4.3aAnswer(a,b,c,d) ← R(a,b,c) AND S(b,c,d)Exercise 5.4.3bAnswer(b,c,d,e) ← S(b,c,d) AND T(d,e)Exercise 5.4.3cAnswer(a,b,c,d,e) ← R(a,b,c) AND S(b,c,d) AND T(d,e)Exercise 5.4.4a)Answer(rx,ry,rz,sx,sy,sz) ← R(rx,ry,rz) AND S(sx,sy,sz) AND rx = syb)Answer(rx,ry,rz,sx,sy,sz) ← R(rx,ry,rz) AND S(sx,sy,sz) AND rx < sy AND ry < szc)Answer(rx,ry,rz,sx,sy,s z) ← R(rx,ry,rz) AND S(sx,sy,sz) AND rx < syAnswer(rx,ry,rz,sx,sy,sz) ← R(rx,ry,rz) AND S(sx,sy,sz) AND ry < szd)Answer(rx,ry,rz,sx,sy,sz) ← R(rx,ry,rz) AND S(sx,sy,sz) AND rx = sye)Answer(rx,ry,rz,sx,sy,sz) ← R(rx,ry,rz) AND S(sx,sy,sz) AND rx = syAnswe r(rx,ry,rz,sx,sy,sz) ← R(rx,ry,rz) AND S(sx,sy,sz) AND ry ≥ szf)Answer(rx,ry,rz,sx,sy,sz) ← R(rx,ry,rz) AND S(sx,sy,sz) AND rx ≥ sy AND rx ≥ szAnswer(rx,ry,rz,sx,sy,sz) ← R(rx,ry,rz) AND S(sx,sy,sz) AND ry ≥ szExercise 5.4.5aR1 := πx,y(Q R)Exercise 5.4.5bR1 := ρR1(x,z)(Q)R2 := ρR2(z,y)(Q)R3 := πx,y(R1 (R1.z = R2.z) R2)Exercise 5.4.5cR1 := πx,y(Q R)R2 := σx < y(R1)。
数据库系统基础教程第五章答案
数据库系统基础教程第五章答案Exercise 5.1.1 As a set:Average = 2.37 As a bag:Average = 2.48 Exercise 5.1.2Average = 218 As a bag:Average = 215 Exercise 5.1.3a As a set:18As a bag:bore1516141615151418Exercise 5.1.3bπ(Ships Classes)boreExercise 5.1.4aFor bags:On the left-hand side:Given bags R and S where a tuple t appears n and m times respectively, the union of bags R and S will have tuple t appear n + m times. The further union of bag T with the tuple t appearing o times will havetuple t appear n + m + o times in the final result.On the right-hand side:Given bags S and T where a tuple t appears m and o times respectively,the union of bags R and S will have tuple t appear m + o times. Thefurther union of bag R with the tuple t appearing n times will havetuple t appear m + o + n times in the final result.For sets:This is a similar case when dealing with bags except the tuple t can only appear at most once in each set. The tuple t only appears in the result if all the sets have the tuple t. Otherwise, the tuple t will not appear in the result. Since we cannot have duplicates, the result only has at most one copy of the tuple t.Exercise 5.1.4bFor bags:On the left-hand side:Given bags R and S where a tuple t appears n and m times respectively,the intersection of bags R and S will have tuple t appear min( n, m )times. The further intersection of bag T with the tuple t appearing otimes will produce tuple t min( o, min( n, m ) ) times in the finalresult.On the right-hand side:Given bags S and T where a tuple t appears m and o times respectively,the intersection of bags R and S will have tuple t appear min( m, o )times. The further intersection of bag R with the tuple t appearing ntimes will produce tuple t min( n, min( m, o ) ) times in the finalresult.The intersection of bags R,S and T will yield a result where tuple t appears min( n,m,o ) times.For sets:This is a similar case when dealing with bags except the tuple t can only appear at most once in each set. The tuple t only appears in the result if all the sets have the tuple t. Otherwise, the tuple t will not appear in the result.Exercise 5.1.4cFor bags:On the left-hand side:Given that tuple r in R, which appears m times, can successfully joinwith tuple s in S, which appears n times, we expect the result tocontain mn copies. Also given that tuple t in T, which appears o times, can successfully join with the joined tuples of r and s, we expect thefinal result to have mno copies.On the right-hand side:Given that tuple s in S, which appears n times, can successfully joinwith tuple t in T, which appears o times, we expect the result tocontain no copies. Also given that tuple r in R, which appears m times,can successfully join with the joined tuples of s and t, we expect thefinal result to have nom copies.The order in which we perform the natural join does not matter for bags.For sets:This is a similar case when dealing with bags except the joined tuples can only appear at most once in each result. If there are tuples r,s,t inrelations R,S,T that can successfully join, then the result will contain a tuple with the schema of their joined attributes. Exercise 5.1.4dFor bags:Suppose a tuple t occurs n and m times in bags R and S respectively. In the union of these two bags R S, tuple t would appear n + m times. Likewise, in the union of these two bags S R, tuple t would appear m + n times. Both sides of the relation yield the same result.For sets:A tuple t can only appear at most one time. Tuple t might appear each in sets R and S one or zero times. The combinations of number of occurrences for tuple t in R and S respectively are (0,0), (0,1), (1,0), and (1,1). Only when tuple t appears in both sets R and S will the union R S have the tuple t. The same reasoning holds when we take the union S R.Therefore the commutative law for union holds.Exercise 5.1.4eFor bags:Suppose a tuple t occurs n and m times in bags R and S respectively. In the intersection of these two bags R ∩ S, tuple t would appear min( n,m ) times. Likewise in the intersection of these two bags S ∩ R, tuple t would appear min( m,n ) times. Both sides of the relation yield the same result.For sets:A tuple t can only appear at most one time. Tuple t might appear each in sets R and S one or zero times. The combinations of number of occurrences for tuplet in R and S respectively are (0,0), (0,1), (1,0), and (1,1). Only when tuple t appears in at least one of the sets R and S will the intersection R ∩ S have the tuple t. The same reasoning holds when we take the intersection S ∩ R.Therefore the commutative law for intersection holds.Exercise 5.1.4fFor bags:Suppose a tuple t occurs n times in bag R and tuple u occurs m times in bag S. Suppose also that the two tuples t,u can successfully join. Then in thenatural join of these two bags R S, the joined tuple would appear nm times. Likewise in the natural join of these two bags S R, the joined tuple would appear mn times. Both sides of the relation yield the same result.For sets:An arbitrary tuple t can only appear at most one time in any set. Tuples u,v might appear respectively in sets R and S one or zero times. The combinations of number of occurrences for tuples u,v in R and S respectively are (0,0), (0,1), (1,0), and (1,1). Only when tuple u exists in R and tuple v exists in S will the natural join R S have the joined tuple. The same reasoning holds when we take the natural join S R.Therefore the commutative law for natural join holds.Exercise 5.1.4gFor bags:Suppose tuple t appears m times in R and n times in S. If we take the union of R and S first, we will get a relation where tuple t appears m + n times. Taking the projection of a list of attributes L will yield a resultingrelation where the projected attributes from tuple t appear m + n times. If we take the projection of the attributes in list L first, then the projected attributes from tuple t would appear m times from R and n times from S. The union of these resulting relations would have the projected attributes oftuple t appear m + n times.For sets:An arbitrary tuple t can only appear at most one time in any set. Tuple tmight appear in sets R and S one or zero times. The combinations of number of occurrences for tuple t in R and S respectively are (0,0), (0,1), (1,0), and (1,1). Only when tuple t exists in R or S (or both R and S) will the projected attributes of tuple t appear in the result.Therefore the law holds.Exercise 5.1.4hFor bags:Suppose tuple t appears u times in R, v times in S and w times in T. On theleft hand side, the intersection of S and T would produce a result where tuple t would appear min(v , w) times. With the addition of the union of R, the overall result would have u + min(v , w) copies of tuple t. On the right hand side, we would get a result of min(u + v, u + w) copies of tuple t. The expressions on both the left and right sides are equivalent.For sets:An arbitrary tuple t can only appear at most one time in any set. Tuple tmight appear in sets R,S and T one or zero times. The combinations of numberof occurrences for tuple t in R, S and T respectively are (0,0,0), (0,0,1), (0,1,0), (0,1,1), (1,0,0), (1,0,1), (1,1,0) and (1,1,1). Only when tuple t appears in R or in both S and T will the result have tuple t.Therefore the distributive law of union over intersection holds.Exercise 5.1.4iSuppose that in relation R, u tuples satisfy condition C and v tuples satisfy condition D. Suppose also that w tuples satisfy both conditions C and D where w≤ min(v , w). Then the left hand side will return those w tuples. On the(R) produces u tuples and σD(R) produces v tuples. However, right hand side, σCwe know the intersection will produce the same w tuples in the result.。
《数据库原理与应用》课后习题参考答案
《数据库原理与应用》课后习题参考答案《数据库原理与应用》课后习题参考答案第一章作业参考答案1. 单选题 C C D B C2. 判断题对错错错对3填空题网状模型用户商业智能数据挖掘系统设计4简答题1)数据模型是指描述事物对象的数据组成、数据关系、数据约束的抽象结构及其说明。
数据模型是指描述事物对象的数据组成、数据关系、数据约束的抽象结构及其说明。
数据模型是指描述事物对象的数据组成、数据关系、数据约束的抽象结构及其说明。
3)数据约束:用于描述数据结构中数据之间的语义联系、数据之间的制约和依存关系,以及数据动态变化的规则。
主流数据库采用关系图模型。
数据库典型数据模型:层次数据模型网状数据模型关系数据模型其它数据模型(如对象数据模型、键值对数据模型、列式数据模型。
)2)数据库——是一种依照特定数据模型组织、存储和管理数据的文件,数据库文件一般存放在辅助存储器以便长久保存。
数据库具有如下特点:数据不重复存放;提供给多种应用程序访问;数据结构独立于使用它的应用程序;对数据增、删、改、检索由统一软件进行管理和控制。
3)数据库(Database)是一种依照特定模型组织、存储和管理数据的数据结构。
在数据库中,不仅存放了数据,而且还存放了数据与数据之间的关系。
数据库内部元素:用户表:用户在数据库中创建的数据库表;系统表:数据库中系统自带的数据库表;视图:数据库中用于对数据进行查询的虚拟表;索引:数据库中用于加快数据查询的索引项;约束:数据库中对数据、数据关系施加的规则;存储过程:数据库内部完成特定功能处理的程序;触发器:数据库内部因数据变化自动执行的一类存储过程等等4)数据库系统包括:用户、数据库应用程序、数据库管理系统和数据库四个组成要素。
5)数据库管理系统(Database Manage System,DBMS )——是一种专门用来创建数据库、管理数据库、维护数据库,并提供对数据库访问的系统软件。
数据库管理系统(DBMS)主要功能:创建数据库和表; 创建支持结构,如索引等; 读取数据库数据 ; 修改数据库数据; 维护数据库结构; 执行规则; 并发控制; 提供安全性; 执行备份和恢复等等第二章作业参考答案1 单选题 C B D A A2. 判断题对对错对错3填空题全外连接数据约束候选键用户定义完整性4简答题外码键1)在关系模型中,使用“关系”来存储“实体”中的数据。
《数据库系统原理》04735课后习题答案(2018版)
答案仅供参考第一章数据库系统概述选择题B、B、A简答题1.请简述数据,数据库,数据库管理系统,数据库系统的概念。
P27数据是描述事物的记录符号,是指用物理符号记录下来的,可以鉴别的信息。
数据库即存储数据的仓库,严格意义上是指长期存储在计算机中的有组织的、可共享的数据集合。
数据库管理系统是专门用于建立和管理数据库的一套软件,介于应用程序和操作系统之间。
数据库系统是指在计算机中引入数据库技术之后的系统,包括数据库、数据库管理系统及相关实用工具、应用程序、数据库管理员和用户。
2.请简述早数据库管理技术中,与人工管理、文件系统相比,数据库系统的优点。
数据共享性高数据冗余小易于保证数据一致性数据独立性高可以实施统一管理与控制减少了应用程序开发与维护的工作量3.请简述数据库系统的三级模式和两层映像的含义。
P31答:数据库的三级模式是指数据库系统是由模式、外模式和内模式三级工程的,对应了数据的三级抽象。
两层映像是指三级模式之间的映像关系,即外模式/模式映像和模式/内模式映像。
4.请简述关系模型与网状模型、层次模型的区别。
P35使用二维表结构表示实体及实体间的联系建立在严格的数学概念的基础上概念单一,统一用关系表示实体和实体之间的联系,数据结构简单清晰,用户易懂易用存取路径对用户透明,具有更高的数据独立性、更好的安全保密性。
第二章关系数据库选择题C、C、D简答题1.请简述关系数据库的基本特征。
P48答:关系数据库的基本特征是使用关系数据模型组织数据。
2.请简述什么是参照完整性约束。
P55答:参照完整性约束是指:若属性或属性组F是基本关系R的外码,与基本关系S的主码K 相对应,则对于R中每个元组在F上的取值只允许有两种可能,要么是空值,要么与S中某个元组的主码值对应。
3.请简述关系规范化过程。
答:对于存在数据冗余、插入异常、删除异常问题的关系模式,应采取将一个关系模式分解为多个关系模式的方法进行处理。
一个低一级范式的关系模式,通过模式分解可以转换为若干个高一级范式的关系模式,这就是所谓的规范化过程。
(完整版)数据库系统基础教程第五章答案
Exercise 5.1.1 As a set:speed2.662.101.422.803.202.202.001.863.06 Average = 2.37 As a bag:speed2.662.101.422.803.203.202.202.202.002.801.862.803.06 Average = 2.48 Exercise 5.1.2 As a set:hd25080320200300160 Average = 218 As a bag:hd2502508025025032020025025030016016080 Average = 215 Exercise 5.1.3a As a set:bore15161418As a bag:bore1516141615151418Exercise 5.1.3bπbore(Ships Classes)Exercise 5.1.4aFor bags:On the left-hand side:Given bags R and S where a tuple t appears n and m times respectively, the union of bags R and S will have tuple t appear n + m times. The further union of bag T with the tuple t appearing o times will have tuple t appear n + m + o times in the final result.On the right-hand side:Given bags S and T where a tuple t appears m and o times respectively, the union of bags R and S will have tuple t appear m + o times. The further union of bag R with the tuple t appearing n times will have tuple t appear m + o + n times in the final result.For sets:This is a similar case when dealing with bags except the tuple t can only appear at most once in each set. The tuple t only appears in the result if all the sets have the tuple t. Otherwise, the tuple t will not appear in the result. Since we cannot have duplicates, the result only has at most one copy of the tuple t.Exercise 5.1.4bFor bags:On the left-hand side:Given bags R and S where a tuple t appears n and m times respectively, the intersectionof bags R and S will have tuple t appear min( n, m ) times. The further intersection of bag T with the tuple t appearing o times will produce tuple t min( o, min( n, m ) ) times in the final result.On the right-hand side:Given bags S and T where a tuple t appears m and o times respectively, the intersection of bags R and S will have tuple t appear min( m, o ) times. The further intersection of bag R with the tuple t appearing n times will produce tuple t min( n, min( m, o ) ) times in thefinal result.The intersection of bags R,S and T will yield a result where tuple t appears min( n,m,o ) times. For sets:This is a similar case when dealing with bags except the tuple t can only appear at most once in each set. The tuple t only appears in the result if all the sets have the tuple t. Otherwise, the tuple t will not appear in the result.Exercise 5.1.4cFor bags:On the left-hand side:Given that tuple r in R, which appears m times, can successfully join with tuple s in S,which appears n times, we expect the result to contain mn copies. Also given that tuple tin T, which appears o times, can successfully join with the joined tuples of r and s, weexpect the final result to have mno copies.On the right-hand side:Given that tuple s in S, which appears n times, can successfully join with tuple t in T,which appears o times, we expect the result to contain no copies. Also given that tuple rin R, which appears m times, can successfully join with the joined tuples of s and t, weexpect the final result to have nom copies.The order in which we perform the natural join does not matter for bags.For sets:This is a similar case when dealing with bags except the joined tuples can only appear at most once in each result. If there are tuples r,s,t in relations R,S,T that can successfully join, then the result will contain a tuple with the schema of their joined attributes.Exercise 5.1.4dFor bags:Suppose a tuple t occurs n and m times in bags R and S respectively. In the union of these two bags R ⋃ S, tuple t would appear n + m times. Likewise, in the union of these two bags S ⋃ R, tuple t would appear m + n times. Both sides of the relation yield the same result.For sets:A tuple t can only appear at most one time. Tuple t might appear each in sets R and S one or zero times. The combinations of number of occurrences for tuple t in R and S respectively are (0,0), (0,1), (1,0), and (1,1). Only when tuple t appears in both sets R and S will the union R ⋃ S have the tuple t. The same reasoning holds when we take the union S ⋃ R.Therefore the commutative law for union holds.Exercise 5.1.4eFor bags:Suppose a tuple t occurs n and m times in bags R and S respectively. In the intersection of these two bags R ∩ S, tuple t would appear min( n,m ) times. Likewise in the intersection of these two bags S ∩ R, tuple t would appear min( m,n ) times. Both sides of the relation yield the same result.For sets:A tuple t can only appear at most one time. Tuple t might appear each in sets R and S one or zero times. The combinations of number of occurrences for tuple t in R and S respectively are (0,0), (0,1), (1,0), and (1,1). Only when tuple t appears in at least one of the sets R and S will the intersection R ∩ S have the tuple t. The same reasoning holds when we take the intersection S ∩R.Therefore the commutative law for intersection holds.Exercise 5.1.4fFor bags:Suppose a tuple t occurs n times in bag R and tuple u occurs m times in bag S. Suppose also that the two tuples t,u can successfully join. Then in the natural join of these two bags R S, the joined tuple would appear nm times. Likewise in the natural join of these two bags S R, the joined tuple would appear mn times. Both sides of the relation yield the same result.For sets:An arbitrary tuple t can only appear at most one time in any set. Tuples u,v might appear respectively in sets R and S one or zero times. The combinations of number of occurrences for tuples u,v in R and S respectively are (0,0), (0,1), (1,0), and (1,1). Only when tuple u exists in Rand tuple v exists in S will the natural join R S have the joined tuple. The same reasoning holds when we take the natural join S R.Therefore the commutative law for natural join holds.Exercise 5.1.4gFor bags:Suppose tuple t appears m times in R and n times in S. If we take the union of R and S first, we will get a relation where tuple t appears m + n times. Taking the projection of a list of attributes L will yield a resulting relation where the projected attributes from tuple t appear m + n times. If we take the projection of the attributes in list L first, then the projected attributes from tuple t would appear m times from R and n times from S. The union of these resulting relations would have the projected attributes of tuple t appear m + n times.For sets:An arbitrary tuple t can only appear at most one time in any set. Tuple t might appear in sets R and S one or zero times. The combinations of number of occurrences for tuple t in R and S respectively are (0,0), (0,1), (1,0), and (1,1). Only when tuple t exists in R or S (or both R and S) will the projected attributes of tuple t appear in the result.Therefore the law holds.Exercise 5.1.4hFor bags:Suppose tuple t appears u times in R, v times in S and w times in T. On the left hand side, the intersection of S and T would produce a result where tuple t would appear min(v , w) times. With the addition of the union of R, the overall result would have u + min(v , w) copies of tuple t. On the right hand side, we would get a result of min(u + v, u + w) copies of tuple t. The expressions on both the left and right sides are equivalent.For sets:An arbitrary tuple t can only appear at most one time in any set. Tuple t might appear in sets R,S and T one or zero times. The combinations of number of occurrences for tuple t in R, S and T respectively are (0,0,0), (0,0,1), (0,1,0), (0,1,1), (1,0,0), (1,0,1), (1,1,0) and (1,1,1). Only when tuple t appears in R or in both S and T will the result have tuple t.Therefore the distributive law of union over intersection holds.Exercise 5.1.4iSuppose that in relation R, u tuples satisfy condition C and v tuples satisfy condition D. Suppose also that w tuples satisfy both conditions C and D where w≤ min(v , w). Then the left hand side will return those w tuples. On the right hand side, σC(R) produces u tuples and σD(R) produces v tuples. However, we know the intersection will produce the same w tuples in the result.When considering bags and sets, the only difference is bags allow duplicate tuples while sets only allow one copy of the tuple. The example above applies to both cases.Therefore the law holds.Exercise 5.1.5aFor sets, an arbitrary tuple t appears on the left hand side if it appears in both R,S and not in T. The same is true for the right hand side.As an example for bags, suppose that tuple t appears one time each in both R,T and two times in S. The result of the left hand side would have zero copies of tuple t while the right hand side would have one copy of tuple t.Therefore the law holds for sets but not for bags.Exercise 5.1.5bFor sets, an arbitrary tuple t appears on the left hand side if it appears in R and either S or T. This is equivalent to saying tuple t only appears when it is in at least R and S or in R and T. The equivalence is exactly the right side’s expression.As an example for bags, suppose that tuple t appears one time in R and two times each in S and T. Then the left hand side would have one copy of tuple t in the result while the right hand side would have two copies of tuple t.Therefore the law holds for sets but not for bags.Exercise 5.1.5cFor sets, an arbitrary tuple t appears on the left hand side if it satisfies condition C, condition D or both condition C and D. On the right hand side, σC(R) selects those tuples that satisfy condition C while σD(R) selects those tuples that satisfy condition D. However, the union operator will eliminate duplicate tuples, namely those tuples that satisfy both condition C and D. Thus we are ensured that both sides are equivalent.As an example for bags, we only need to look at the union operator. If there are indeed tuples that satisfy both conditions C and D, then the right hand side will contain duplicate copies of those tuples. The left hand side, however, will only have one copy for each tuple of the original set of tuples.A+B A2B210154910164167916 Exercise 5.2.1bB+1C-1103334431143 Exercise 5.2.1cA B0101232434 Exercise 5.2.1dB C010224253434A B01232434 Exercise 5.2.1fB C0124253402 Exercise 5.2.1gA SUM(B)022734 Exercise 5.2.1hB AVG(C)0 1.52 4.534 Exercise 5.2.1iA23Exercise 5.2.1jA MAX(C)24 Exercise 5.2.1kA B C23423401┴01┴24┴34┴Exercise 5.2.1lA B C234234┴01┴24┴25┴02 Exercise 5.2.1mA B C23423401┴01┴24┴34┴┴01┴24┴25┴02Exercise 5.2.1nA R.B S.B C0124012501340134012401250134013423┴┴24┴┴34┴┴┴┴01┴┴02Exercise 5.2.2aApplying the δ operator on a relation with no duplicates will yield the same relation. Thus δ is idempotent.Exercise 5.2.2bThe result of πL is a relation over the list of attributes L. Performing the projection again will return the same relation because the relation only contains the list of attributes L. Thus πL is idempotent.Exercise 5.2.2cThe result of σC is a relation where condition C is satisfied by every tuple. Performing the selection again will return the same relation because the relation only contains tuples that satisfy the condition C. Thus σC is idempotent.Exercise 5.2.2dThe result of γL is a relation whose schema consists of the grouping attributes and the aggregated attributes. If we perform the same grouping operation, there is no guarantee that the expression would make sense. The grouping attributes will still appear in the new result. However, the aggregated attributes may or may not appear correctly. If the aggregated attribute is given a different name than the original attribute, then performing γL would not make sense because it contains an aggregation for an attribute name that does not exist. In this case, the resultingrelation would, according to the definition, only contain the grouping attributes. Thus, γL is not idempotent.Exercise 5.2.2eThe result of τ is a sorted list of tuples based on some attributes L. If L is not the entire schema of relation R, then there are attributes that are not sorted on. If in relation R there are two tuples that agree in all attributes L and disagree in some of the remaining attributes not in L, then it is arbitrary as to which order these two tuples appear in the result. Thus, performing the operation τmultiple times can yield a different relation where these two tuples are swapped. Thus, τ is not idempotent.Exercise 5.2.3If we only consider sets, then it is possible. We can take πA(R) and do a product with itself. From this product, we take the tuples where the two columns are equal to each other.If we consider bags as well, then it is not possible. Take the case where we have the two tuples (1,0) and (1,0). We wish to produce a relation that contains tuples (1,1) and (1,1). If we use the classical operations of relational algebra, we can either get a result where there are no tuples or four copies of the tuple (1,1). It is not possible to get the desired relation because no operation can distinguish between the original tuples and the duplicated tuples. Thus it is not possible to get the relation with the two tuples (1,1) and (1,1).Exercise 5.3.1a)Answer(model) ← PC(model,speed,_,_,_) AND speed ≥ 3.00b)Answer(maker) ← Laptop(model,_,_,hd,_,_) AND Product(maker,model,_) AND hd ≥100c)Answer(model,price) ← PC(model,_,_,_,price) AND Product(maker,model,_) ANDmaker=’B’Answer(model,price) ← Laptop(model,_,_,_,_,price) AND Product(maker,model,_)AND maker=’B’Answer(model,price) ← Printer(model,_,_,price) AND Product(maker,model,_) ANDmaker=’B’d)Answer(model) ← Printer(model,color,type,_) AND color=’true’ AND type=’laser’e)PCMaker(maker) ← Product(maker,_,type) AND type=’pc’LaptopMaker(maker) ← Product(maker,_,type) AND type=’laptop’Answer(maker) ← LaptopMaker(maker) AND NOT PCMaker(maker)f)Answer(hd) ← PC(model1,_,_,hd,_) AND PC(model2,_,_,hd,_) AND model1 <>model2g)Answer(model1,model2) ← PC(model1,speed, ram,_,_) ANDPC(model2,_speed,ram,_,_) AND model1 < model2h)FastComputer(model) ← PC(model,speed,_,_,_) AND speed ≥ 2.80FastComputer(model) ← Laptop(model,speed,_,_,_,_) AND speed ≥ 2.80Answer(maker) ← Product(maker,model1,_) AND Product(maker,model2,_) ANDFastComputer(model1) AND FastComputer(model2) AND model1 <> model2i)Computers(model,speed) ← PC(model,speed,_,_,_)Computers(model,speed) ← Laptop(model,speed,_,_,_,_)SlowComputers(model) ← Computers(model,speed) AND Computers(model1,speed1) AND speed < speed1FastestComputers(model) ← Computers(model,_) AND NOT SlowComputers(model)Answer(maker) ← FastestComputers(model) AND Product(maker,model,_) j)PCs(maker,speed) ← PC(model,speed,_,_,_) AND Product(maker,model,_) Answer(maker) ← PCs(maker,speed) AND PCs(maker,speed1) ANDPCs(maker,speed2) AND speed <> speed1 AND speed <> speed2 AND speed1 <>speed2k)PCs(maker,model) ← Product(maker,model,type) AND type=’pc’Answer(maker) ← PCs(maker,model) AND PCs(maker,model1) ANDPCs(maker,model2) AND PCs(maker,model3) AND model <> model1 AND model <> model2 AND model1 <> model2 AND (model3 = model OR model3 = model1 ORmodel3 = model2)Exercise 5.3.2a)Answer(class,country) ← Classes(class,_,country,_,bore,_) AND bore ≥ 16b)Answer(name) ← Ships(name,_,launched) AND launched < 1921c)Answer(ship) ← Outcomes(ship,battle,result) AND battle=’Denmark Strait’ AND result= ‘sunk’d)Answer(name) ← Classes(class,_,_,_,_,displacement) AND Ships(name,class,launched)AND displacement > 35000 AND launched > 1921e)Answer(name,displacement,numGuns) ← Classes(class,_,_,numGuns,_,displacement)AND Ships(name,class,_) AND Outcomes (ship,battle,_) AND battle=’Guadalcanal’AND ship=namef)Answer(name) ← Ships(name,_,_)Answer(name) ← Outcomes(name,_,_) AND NOT Answer(name)g)MoreThanOne(class) ← Ships(name,class,_) AND Ships(name1,class,_) AND name <>name1Answer(class) ← Classes(class,_,_,_,_,_) AND NOT MoreThanOne(class)h)Battleship(country) ← Classes(_,type,country,_,_,_) AND type=’bb’Battlecruiser(country) ← Classes(_,type,country,_,_,_) AND type=’bc’Answer(country) ← Battleship(country) AND Battlecruiser(country)i)Results(ship,result,date) ← Battles(name,date) AND Outcomes(ship,battle,result) ANDbattle=nameAnswer(ship) ← Results(ship,result,date) AND Results(ship,_,date1) ANDresult=’damaged’ AND date < date1Exercise 5.3.3Answer(x,y) ← R(x,y) AND z = zExercise 5.4.1aAnswer(a,b,c) ← R(a,b,c)Answer(a,b,c) ← S(a,b,c)Exercise 5.4.1bAnswer(a,b,c) ← R(a,b,c) AND S(a,b,c)Exercise 5.4.1cAnswer(a,b,c) ← R(a,b,c) AND NOT S(a,b,c)Exercise 5.4.1dUnion(a,b,c) ← R(a,b,c)Union(a,b,c) ← S(a,b,c)Answer(a,b,c) ← Union(a,b,c) AND NOT T(a,b,c)Exercise 5.4.1eJ(a,b,c) ← R(a,b,c) AND NOT S(a,b,c)K(a,b,c) ← R(,a,b,c) AND NOT T(a,b,c)Answer(a,b,c) ← J(a,b,c) AND K(a,b,c)Exercise 5.4.1fAnswer(a,b) ← R(a,b,_)Exercise 5.4.1gJ(a,b) ← R(a,b,_)K(a,b) ← S(_,a,b)Answer(a,b) ← J(a,b) AND K(a,b)Exercise 5.4.2aAnswer(x,y,z) ← R(x,y,z) AND x = yExercise 5.4.2bAnswer(x,y,z) ← R(x,y,z) AND x < y AND y < z Exercise 5.4.2cAnswer(x,y,z) ← R(x,y,z) AND x < yAnswer(x,y,z) ← R(x,y,z) AND y < zExercise 5.4.2dChange:NOT(x < y OR x > y)To:x ≥ y AND x ≤ yThe above simplifies to x = yAnswer(x,y,z) ← R(x,y,z) AND x = yExercise 5.4.2eChange:NOT((x < y OR x > y) AND y < z)NOT(x < y OR x > y) OR y ≥ z(x ≥ y AND x ≤ y) OR y ≥ zTo:x = y OR y ≥ zAnswer(x,y,z) ← R(x,y,z) AND x = yAnswer(x,y,z) ← R(x,y,z) AND y ≥ zExercise 5.4.2fChange:NOT((x < y OR x < z) AND y < z)NOT(x < y OR x < z) OR y ≥ z To:(x ≥ y AND x ≥ z) OR y ≥ zAnswer(x,y,z) ← R(x,y,z) AND x ≥ y AND x ≥ zAnswer(x,y,z) ← R(x,y,z) AND y ≥zExercise 5.4.3aAnswer(a,b,c,d) ← R(a,b,c) AND S(b,c,d)Exercise 5.4.3bAnswer(b,c,d,e) ← S(b,c,d) AND T(d,e)Exercise 5.4.3cAnswer(a,b,c,d,e) ← R(a,b,c) AND S(b,c,d) AND T(d,e)Exercise 5.4.4a)Answer(rx,ry,rz,sx,sy,sz) ← R(rx,ry,rz) AND S(sx,sy,sz) AND rx = syb)Answer(rx,ry,rz,sx,sy,sz) ← R(rx,ry,rz) AND S(sx,sy,sz) AND rx < sy AND ry < szc)Answer(rx,ry,rz,sx,sy,sz) ← R(rx,ry,rz) AND S(sx,sy,sz) AND rx < syAnswer(rx,ry,rz,sx,sy,sz) ← R(rx,ry,rz) AND S(sx,sy,sz) AND ry < szd)Answer(rx,ry,rz,sx,sy,sz) ← R(rx,ry,rz) AND S(sx,sy,sz) AND rx = sye)Answer(rx,ry,rz,sx,sy,sz) ← R(rx,ry,rz) AND S(sx,sy,sz) AND rx = syAnswer(rx,ry,rz,sx,sy,sz) ← R(rx,ry,rz) AND S(sx,sy,sz) AND ry ≥ szf)Answer(rx,ry,rz,sx,sy,sz) ← R(rx,ry,rz) AND S(sx,sy,sz) AND rx ≥ sy AND rx ≥ szAnswer(rx,ry,rz,sx,sy,sz) ← R(rx,ry,rz) AND S(sx,sy,sz) AND ry ≥ szExercise 5.4.5aR1 := πx,y(Q R)Exercise 5.4.5bR1 := ρR1(x,z)(Q)R2 := ρR2(z,y)(Q)R3 := πx,y(R1 (R1.z = R2.z) R2)Exercise 5.4.5cR1 := πx,y(Q R)R2 := σx < y(R1)。
数据库系统原理(2018年版)课后习题参考答案解析
第三代数据库系统必须保持或集成第二代数据库系统技术
第三代数据库系统必须对其他系统开放
2.描述数据仓库粒度的概念P182
粒度是指数据仓库数据单位中保存数据的细化或综合程度
3.描述数据挖掘技术的能P183
概念描述
关联分析
分类与预测
聚类
孤立点检测
趋势和演变分析
视图的内容是由存储在数据库中进行查询操作的SQL语句定义的,它的列数据与行数据均来自于定义视图的查询所引用的基本表。
视图不适宜数据集的形式存储在数据库中的,它所对应的数据实际上是存储在视图所引用的基本表中的。
视图是用来查看存储在别处的数据的一种虚拟表,本身不存储数据。
第五章 数据库编程
简答题
1.请简述存储过程的概念P125
答:参照完整性约束是指:若属性或属性组F是基本关系R的外码,与基本关系S的主码K相对应,则对于R中每个元组在F上的取值只允许有两种可能,要么是空值,要么与S中某个元组的主码值对应。
3.请简述关系规范化过程。
答:对于存在数据冗余、插入异常、删除异常问题的关系模式,应采取将一个关系模式分解为多个关系模式的方法进行处理。一个低一级范式的关系模式,通过模式分解可以转换为若干个高一级范式的关系模式,这就是所谓的规范化过程。
数据库系统是指在计算机中引入数据库技术之后的系统,包括数据库、数据库管理系统及相关实用工具、应用程序、数据库管理员和用户。
2.请简述早数据库管理技术中,与人工管理、文件系统相比,数据库系统的优点。
数据共享性高
数据冗余小
易于保证数据一致性
数据独立性高
可以实施统一管理与控制
减少了应用程序开发与维护的工作量
(完整版)数据库原理第五版习题答案
答:
实体:客观存在并可以相互区分的事物叫实体。实体型:具有相同属性的实体具有相同的特征和性质,用实体名及其属性名集合来抽象和刻画同类实体,称为实体型。实体集:同型实体的集合称为实体集。属性:实体所具有的某一特性,一个实体可由若干个属性来刻画。码:惟一标识实体的属性集称为码。实体联系图(E一R图):提供了表示实体型、属性和联系的方法:·实体型:用矩形表示,矩形框内写明实体名;·属性:用椭圆形表示,并用无向边将其与相应的实体连接起来;·联系:用菱形表示,菱形框内写明联系名,并用无向边分别与有关实体连接起来,同时在无向边旁标上联系的类型(1 : 1 , 1 : n或m : n)。
( 4)数据库管理系统(DataBase Management sytem,简称DBMs ):数据库管理系统是位于用户与操作系统之间的一层数据管理软件,用于科学地组织和存储数据、高效地获取和维护数据。DBMS的主要功能包括数据定义功能、数据操纵功能、数据库的运行管理功能、数据库的建立和维护功能。解析DBMS是一个大型的复杂的软件系统,是计算机中的基础软件。目前,专门研制DBMS的厂商及其研制的DBMS产品很多。著名的有美国IBM公司的DBZ关系数据库管理系统和IMS层次数据库管理系统、美国Oracle公司的orade关系数据库管理系统、s油ase公司的s油ase关系数据库管理系统、美国微软公司的SQL Serve,关系数据库管理系统等。
11.试给出一个实际部门的E一R图,要求有三个实体型,而且3个实体型之间有多对多联系。3个实体型之间的多对多联系和三个实体型两两之间的三个多对多联系等价吗?为什么?
答:
3个实体型之间的多对多联系和3个实体型两两之间的3个多对多联系是不等价,因为它们拥有不同的语义。3个实体型两两之间的三个多对多联系如下图所示。
(完整版)数据库原理第五版习题答案
1.试述数据、数据库、数据库系统、数据库管理系统的概念。
答:
( l)数据(Data ):描述事物的符号记录称为数据。数据的种类有数字、文字、图形、图像、声音、正文等。数据与其语义是不可分的。解析在现代计算机系统中数据的概念是广义的。早期的计算机系统主要用于科学计算,处理的数据是整数、实数、浮点数等传统数学中的数据。现代计算机能存储和处理的对象十分广泛,表示这些对象的数据也越来越复杂。数据与其语义是不可分的。500这个数字可以表示一件物品的价格是500元,也可以表示一个学术会议参加的人数有500人,还可以表示一袋奶粉重500克。
20.试述数据库系统三级模式结构,这种结构的优点是什么?
答:
数据库系统的三级模式结构由外模式、模式和内模式组成。(参见书上图1 . 29 )外模式,亦称子模式或用户模式,是数据库用户(包括应用程序员和最终用户)能够看见和使用的局部数据的逻辑结构和特征的描述,是数据库用户的数据视图,是与某一应用有关的数据的逻辑表示。模式,亦称逻辑模式,是数据库中全体数据的逻辑结构和特征的描述,是所有用户的公共数据视图。模式描述的是数据的全局逻辑结构。外模式涉及的是数据的局部逻辑结构,通常是模式的子集。内模式,亦称存储模式,是数据在数据库系统内部的表示,即对数据的物理结构和存储方式的描述。数据库系统的三级模式是对数据的三个抽象级别,它把数据的具体组织留给DBMs管理,使用户能逻辑抽象地处理数据,而不必关心数据在计算机中的表示和存储。为了能够在内部实现这三个抽象层次的联系和转换,数据库系统在这三级模式之间提供了两层映像:外模式/模式映像和模式/内模式映像。正是这两层映像保证了数据库系统中的数据能够具有较高的逻辑独立性和物理独立性。
答:
关系模型由关系数据结构、关系操作集合和关系完整性约束三部分组成。在用户观点下,关系模型中数据的逻辑结构是一张二维表,它由行和列组成。( l)关系:一个关系对应通常说的一张表;( 2)属性:表中的一列即为一个属性;( 3)域:属性的取值范围;( 4)元组:表中的一行即为一个元组;( 5)主码:表中的某个属性组,它可以惟一确定一个元组;( 6)分量:元组中的一个属性值;( 7)关系模式:对关系的描述,一般表示为关系名(属性1,属性2,…,属性n )
(完整版)数据库原理课后题答案
第1章1.试恳数据、数据库、数据库系统、数据库管理系统的概念。
答:(1)数据:描述事物的符号记录成为数据。
数据的种类有数字、文字、图形、图像、声音、正文等。
数据与其语义是不可分的。
(2)数据库:数据库是长期储存在计算机内的、有组织的、可共享的数据集合。
数据库中的数据按照一定的数据模型组织。
描述和储存,具有较小的冗余度、较高的数据独立性和易扩展性,并可为各种用户共享。
(3)数据库系统:数据库系统是指在计算机系统中引入数据库后的系统构成,一般由数据库、数据库管理系统(及其开发人具)、应用系统、数据库管理员构成。
(4)数据库管理系统:数据库管理系统是位于用户与操作系统之间的一层数据管理软件,用于科学地组织和存储数据、高效地获取和维护数据。
DBMS的主要功能包括数据定义功能、数据操作功能、数据库的建立和维护功能。
6. 试述数据库系统三级模式结构,这种结构的优点是什么?答:数据库系统的三级模式机构由外模式、模式和内模式组成。
外模式,亦称子模式或用户模式,是数据库用户(包括应用程序员和最终用户)能够看见和使用的局部数据的逻辑结构和特征的描述,是数据库用户的数据视图,是与某一应用有关的数据的逻辑表示。
模式亦称逻辑模式,是数据库中全体数据呃逻辑结构和特征的描述,是所有用户的公共数据视图。
模式描述的是数据的全局逻辑结构。
外模式涉及的是数据的内部逻辑结构,通常是模式的子集。
内模式,亦称存储模式,是数据在数据库内部的表示,即对数据的物理结构和存储方式的描述。
数据库系统的三级模式是对数据的三个抽象级别,它对数据的具体组织留给DBMS管理,使用户能逻辑抽象地处理数据,而不必关心数据在计算机中的表示和存储。
为了能够在内部实现这三个抽象层次的联系和转换,数据库系统在这三级模式之间提供了两层映像:外模式/模式映像和模式/内模式映像。
正是这两层映像保证了数据库系统中的数据能够具有较高的逻辑独立性和物理独立性。
7. 定义并解释下列术语。
数据库原理及应用第5章课后习题答案
习题51、 理解并给出下列术语的定义:1)设R(U)是一个属性集U 上的关系模式,X 和Y 是U 的子集。
若对于R(U)的任意一个可能的关系r ,r 中不可能存在两个元组在X 上的属性值相等, 而在Y 上的属性值不等, 则称 X 函数确定Y 或 Y 函数依赖于X ,记作X →Y 。
2) 完全函数依赖在R(U)中,如果X →Y ,并且对于X 的任何一个真子集X ’,都有Y 不函数依赖于X ’ ,则称Y 对X 完全函数依赖,记作Y X F −→−3) 部分函数依赖若X →Y ,但Y 不完全函数依赖于X ,则称Y 对X 部分函数依赖,记作Y X p −→−4) 传递函数依赖在R(U)中,如果X →Y ,(Y ⊆X) , Y →X ,Y →Z , 则称Z 对X 传递函数依赖。
记为:Z X T−→−注: 如果Y →X , 即X ←→Y ,则Z 直接依赖于X 。
5)候选码设K 为R (U,F )的属性或属性组合。
若U K F →, 则K 称为R 的侯选码。
6)主码:若候选码多于一个,则选定其中的一个作为主码。
7)外码:关系模式 R 中属性或属性组X 并非 R 的码,但 X 是另一个关系模式的码,则称 X 是R 的外部码(Foreign key )也称外码8)如果一个关系模式R 的所有属性都是不可分的基本数据项,则R ∈1NF.9)若R ∈1NF ,且每一个非主属性完全函数依赖于码,则R ∈2NF 。
10)如果R(U,F )∈2NF ,并且所有非主属性都不传递依赖于主码,则R(U,F )∈3NF 。
11)关系模式R (U ,F )∈1NF ,若X →Y 且Y ⊆ X 时X 必含有码,则R (U ,F ) ∈BCNF 。
12)关系模式R<U ,F>∈1NF ,如果对于R 的每个非平凡多值依赖X →→Y (Y ⊆ X ),X 都含有码,则R ∈4NF 。
2、 关系规范化的操作异常有哪些?1) 数据冗余大2) 插入异常3) 删除异常4) 更新异常3、 第一范式、第二范式和第三范式关系的关系是什么?4、 已知关系模式R(A,B,C,D,E)及其上的函数依赖集合F={A->D,B->C,E-> A},该关系模式的候选码是什么?候选码为:(E,B)5、 已知学生表(学号,姓名,性别,年龄,系编号,系名称),存在的函数依赖集合是{学号->姓名,学号->性别,学号->年龄,学号->系编号,系编号->系名称},判断其满足第几范式。
《数据库系统概论》课后习题及参考答案
《数据库系统概论》课后习题及参考答案D数据库的数据不再面向某个应用而是面向整个系统,因此可以被多个用户、多个应用、用多种不同的语言共享使用。
由于数据面向整个系统,是有结构的数据,不仅可以被多个应用共享使用,而且容易增加新的应用,这就使得数据库系统弹性大,易于扩充。
三、数据独立性高数据独立性包括数据的物理独立性和数据的逻辑独立性。
数据库管理系统的模式结构和二级映象功能保证了数据库中的数据具有很高的物理独立性和逻辑独立性。
四、数据由 DBMS统一管理和控制数据库的共享是并发的共享,即多个用户可以同时存取数据库中的数据甚至可以同时存取数据库中同一个数据。
为此, DBMS 必须提供统一的数据控制功能,包括数据的安全性保护,数据的完整性检查,并发控制和数据库恢复。
6.数据库管理系统的主要功能有哪些?①数据库定义功能;②数据存取功能;③数据库运行管理;④数据库的建立和维护功能。
7.试述数据模型的概念、数据模型的作用和数据模型的三个要素。
数据模型是数据库中用来对现实世界进行抽象的工具,是数据库中用于提供信息表示和操作手段的形式构架。
一般地讲,数据模型是严格定义的概念的集合。
这些概念精确地描述系统的静态特性、动态特性和完整性约束条件。
因此数据模型通常由数据结构、数据操作和完整性约束三部分组成。
①数据结构:是所研究的对象类型的集合,是对系统的静态特性的描述。
②数据操作:是指对数据库中各种对象(型)的实例(值)允许进行的操作的集合,包括操作及有关的操作规则,是对系统动态特性的描述。
③数据的约束条件:是完整性规则的集合,完整性规则是给定的数据模型中数据及其联系所具有的制约和依存规则,用以限定符合数据模型的数据库状态以及状态的变化,以保证数据的正确、有效、相容。
8.试述概念模型的作用。
概念模型实际上是现实世界到机器世界的一个中间层次。
概念模型用于信息世界的建模,是现实世界到信息世界的第一层抽象,是数据库设计人员进行数据库设计的有力工具,也是数据库设计人员和用户之间进行交流的语言。
第五章王珊,萨师煊版《数据库系统概论》讲义及课后习题答案
完整性约束条件分类
六类完整性约束条件
•
静态列级约束 静态元组约束 静态关系约束 动态列级约束 动态元组约束 动态关系约束
• • • • •
完整性约束条件(续)
对象状态 动态 动态列级约束 ④ 静态列级约束 ① 动态元组约束 ⑤ 动态关系约束 ⑥
静态
静态元组约束 静态关系约束 ② ③
列
元组
关系
对象粒度
4. 修改被参照关系中主码的问题
• 两种策略 (1)不允许修改主码 (2)允许修改主码
允许修改主码策略
• 违约操作 ♦要修改被参照关系中某些元组的主码值, 而参照关系中有些元组的外码值正好等 于被参照关系要修改的主码值 ♦要修改参照关系中某些元组的主码值, 而被参照关系中没有任何元组的外码值 等于被参照关系修改后的主码值
允许修改主码策略
例:将Student关系中Sno=950001的元组中Sno 值改为960123。而SC关系中有 4个元组的 Sno=950001 – 级联修改:将SC关系中4个Sno=950001元组 中的Sno值也改为960123。如果参照关系同时 又是另一个关系的被参照关系,则这种修改操 作会继续级联下去。
一般是拒绝执行
• 违反参照完整性的操作:
– 拒绝执行 – 接受这个操作,同时执行一些附加的操作,以保证 数据库的状态正确
三、参照完整性的实现
例:职工-部门数据库包含职工表EMP和部门表DEPT
1 DEPT关系的主码为部门号Deptno 2 EMP关系的主码为职工号Empno, 外码为部门号Deptno 称DEPT为被参照关系或目标关系,EMP为参照关系
3.在参照关系中插入元组时的问题
• 受限插入 – 仅当被参照关系中存在相应的元组,其主码值 与参照关系插入元组的外码值相同时,系统才 执行插入操作,否则拒绝此操作。 • 递归插入 – 首先向被参照关系中插入相应的元组,其主码 值等于参照关系插入元组的外码值,然后向参 照关系插入元组。
数据库系统原理教程课后习题答案
第1章绪论1 .试述数据、数据库、数据库系统、数据库管理系统的概念。
答:( l )数据(Data ) :描述事物的符号记录称为数据。
数据的种类有数字、文字、图形、图像、声音、正文等。
数据与其语义是不可分的。
解析在现代计算机系统中数据的概念是广义的。
早期的计算机系统主要用于科学计算,处理的数据是整数、实数、浮点数等传统数学中的数据。
现代计算机能存储和处理的对象十分广泛,表示这些对象的数据也越来越复杂。
数据与其语义是不可分的。
500 这个数字可以表示一件物品的价格是500 元,也可以表示一个学术会议参加的人数有500 人,还可以表示一袋奶粉重500 克。
( 2 )数据库(DataBase ,简称DB ) :数据库是长期储存在计算机内的、有组织的、可共享的数据集合。
数据库中的数据按一定的数据模型组织、描述和储存,具有较小的冗余度、较高的数据独立性和易扩展性,并可为各种用户共享。
( 3 )数据库系统(DataBas 。
Sytem ,简称DBS ) :数据库系统是指在计算机系统中引入数据库后的系统构成,一般由数据库、数据库管理系统(及其开发工具)、应用系统、数据库管理员构成。
解析数据库系统和数据库是两个概念。
数据库系统是一个人一机系统,数据库是数据库系统的一个组成部分。
但是在日常工作中人们常常把数据库系统简称为数据库。
希望读者能够从人们讲话或文章的上下文中区分“数据库系统”和“数据库”,不要引起混淆。
( 4 )数据库管理系统(DataBase Management sytem ,简称DBMs ) :数据库管理系统是位于用户与操作系统之间的一层数据管理软件,用于科学地组织和存储数据、高效地获取和维护数据。
DBMS 的主要功能包括数据定义功能、数据操纵功能、数据库的运行管理功能、数据库的建立和维护功能。
解析DBMS 是一个大型的复杂的软件系统,是计算机中的基础软件。
目前,专门研制DBMS 的厂商及其研制的DBMS 产品很多。
数据库系统概论第五版课后习题答案
第1章绪论1 .试述数据、数据库、数据库系统、数据库管理系统的概念。
答:( l )数据( Data ) :描述事物的符号记录称为数据。
数据的种类有数字、文字、图形、图像、声音、正文等。
数据与其语义是不可分的。
解析在现代计算机系统中数据的概念是广义的。
早期的计算机系统主要用于科学计算,处理的数据是整数、实数、浮点数等传统数学中的数据。
现代计算机能存储和处理的对象十分广泛,表示这些对象的数据也越来越复杂。
数据与其语义是不可分的。
500 这个数字可以表示一件物品的价格是 500 元,也可以表示一个学术会议参加的人数有 500 人,还可以表示一袋奶粉重 500 克。
( 2 )数据库( DataBase ,简称 DB ) :数据库是长期储存在计算机内的、有组织的、可共享的数据集合。
数据库中的数据按一定的数据模型组织、描述和储存,具有较小的冗余度、较高的数据独立性和易扩展性,并可为各种用户共享。
( 3 )数据库系统( DataBas 。
Sytem ,简称 DBS ) :数据库系统是指在计算机系统中引入数据库后的系统构成,一般由数据库、数据库管理系统(及其开发工具)、应用系统、数据库管理员构成。
解析数据库系统和数据库是两个概念。
数据库系统是一个人一机系统,数据库是数据库系统的一个组成部分。
但是在日常工作中人们常常把数据库系统简称为数据库。
希望读者能够从人们讲话或文章的上下文中区分“数据库系统”和“数据库”,不要引起混淆。
( 4 )数据库管理系统( DataBase Management sytem ,简称 DBMs ) :数据库管理系统是位于用户与操作系统之间的一层数据管理软件,用于科学地组织和存储数据、高效地获取和维护数据。
DBMS 的主要功能包括数据定义功能、数据操纵功能、数据库的运行管理功能、数据库的建立和维护功能。
解析 DBMS 是一个大型的复杂的软件系统,是计算机中的基础软件。
目前,专门研制 DBMS 的厂商及其研制的 DBMS 产品很多。
数据库系统原理与设计万常选版第五章练习题和详细答案
第五章关系数据理论一、选择题1. 为了设计出性能较优的关系模式,必须进行规范化,规范化主要的理论依据是()。
A. 关系规范化理论B. 关系代数理论C.数理逻辑D. 关系运算理论2. 规范化理论是关系数据库进行逻辑设计的理论依据,根据这个理论,关系数据库中的关系必须满足:每一个属性都是()。
A. 长度不变的B. 不可分解的C.互相关联的D. 互不相关的3. 已知关系模式R(A,B,C,D,E)及其上的函数相关性集合F={A→D,B→C ,E→A },该关系模式的候选关键字是()。
A.ABB. BEC.CDD. DE4. 设学生关系S(SNO,SNAME,SSEX,SAGE,SDPART)的主键为SNO,学生选课关系SC(SNO,CNO,SCORE)的主键为SNO和CNO,则关系R(SNO,CNO,SSEX,SAGE,SDPART,SCORE)的主键为SNO和CNO,其满足()。
A. 1NFB.2NFC. 3NFD. BCNF5. 设有关系模式W(C,P,S,G,T,R),其中各属性的含义是:C表示课程,P 表示教师,S表示学生,G表示成绩,T表示时间,R表示教室,根据语义有如下数据依赖集:D={ C→P,(S,C)→G,(T,R)→C,(T,P)→R,(T,S)→R },关系模式W 的一个关键字是()。
A. (S,C)B. (T,R)C. (T,P)D. (T,S)6. 关系模式中,满足2NF的模式()。
A. 可能是1NFB. 必定是1NFC. 必定是3NFD. 必定是BCNF7. 关系模式R中的属性全是主属性,则R的最高范式必定是()。
A. 1NFB. 2NFC. 3NFD. BCNF8. 消除了部分函数依赖的1NF的关系模式,必定是()。
A. 1NFB. 2NFC. 3NFD. BCNF9. 如果A->B ,那么属性A和属性B的联系是()。
A. 一对多B. 多对一C.多对多D. 以上都不是10. 关系模式的候选关键字可以有1个或多个,而主关键字有()。
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
5.1 名词解释(1)SQL模式:SQL模式是表和授权的静态定义。
一个SQL模式定义为基本表的集合。
一个由模式名和模式拥有者的用户名或账号来确定,并包含模式中每一个元素(基本表、视图、索引等)的定义。
(2)SQL数据库:SQL(Structured Query Language),即‘结构式查询语言’,采用英语单词表示和结构式的语法规则。
一个SQL数据库是表的汇集,它用一个或多个SQL模式定义。
(3)基本表:在SQL中,把传统的关系模型中的关系模式称为基本表(Base Table)。
基本表是实际存储在数据库中的表,对应一个关系。
(4)存储文件:在SQL中,把传统的关系模型中的存储模式称为存储文件(Stored File)。
每个存储文件与外部存储器上一个物理文件对应。
(5)视图:在SQL中,把传统的关系模型中的子模式称为视图(View),视图是从若干基本表和(或)其他视图构造出来的表。
(6)行:在SQL中,把传统的关系模型中的元组称为行(row)。
(7)列:在SQL中,把传统的关系模型中的属性称为列(coloumn)。
(8)实表:基本表被称为“实表”,它是实际存放在数据库中的表。
(9)虚表:视图被称为“虚表”,创建一个视图时,只把视图的定义存储在数据词典中,而不存储视图所对应的数据。
(10)相关子查询:在嵌套查询中出现的符合以下特征的子查询:子查询中查询条件依赖于外层查询中的某个值,所以子查询的处理不只一次,要反复求值,以供外层查询使用。
(11)联接查询:查询时先对表进行笛卡尔积操作,然后再做等值联接、选择、投影等操作。
联接查询的效率比嵌套查询低。
(12)交互式SQL:在终端交互方式下使用的SQL语言称为交互式SQL。
(13)嵌入式SQL:嵌入在高级语言的程序中使用的SQL语言称为嵌入式SQL。
(14)共享变量:SQL和宿主语言的接口。
共享变量有宿主语言程序定义,再用SQL 的DECLARE语句说明, SQL语句就可引用这些变量传递数据库信息。
(15)游标:游标是与某一查询结果相联系的符号名,用于把集合操作转换成单记录处理方式。
(16)卷游标:为了克服游标在推进时不能返回的不便,SQL2提供了卷游标技术。
卷游标在推进时不但能沿查询结果中元组顺序从头到尾一行行推进,也能一行行返回。
5.2 对于教学数据库的三个基本表学生 S(S#,SNAME,AGE,SEX)学习 SC(S#,C#,GRADE)课程 C(C#,CNAME,TEACHER)试用SQL的查询语句表达下列查询:(1)检索LIU老师所授课程的课程号和课程名。
SELECT C#,CNAMEFROM CW HERE TEACHER=‘LIU’(2)检索年龄大于23岁的男学生的学号和姓名。
SELECT S#,SNAMEFROM SWHERE (AGE>23) AND (SEX=‘M’)(3)检索至少选修LIU老师所授课程中一门课程的女学生姓名。
SELECT SNAMEFROM SWHERE SEX=‘F’ AND S# IN(SELECT S#FROM SCWHERE C# IN(SELECT C#FROM CWHERE TEACHER=‘LIU’)NOTICE:有多种写法,比如联接查询写法:SELECT SNAMEFROM S,SC,CWHERE SEX=‘F’ AND SC.S#=S.S#AND SC.C#=C.C#AND TEACHER='LIU'但上一种写法更好一些。
(4)检索WANG同学不学的课程的课程号。
SELECT C#FROM CWHERE C# NOT IN(SELECT C#FROM SCWHERE S# IN(SELECT S#FROM SWHERE SNAME='WANG'))(5)检索至少选修两门课程的学生学号。
SELECT DISTINCT X.SNOFROM SC X,SC YWHERE X.SNO=Y.SNO AND O<>ONotice:对表SC进行自连接,X,Y是SC的两个别名。
(6)检索全部学生都选修的课程的课程号与课程名。
SELECT C#,CNAMEFROM CWHERE NOT EXISTS(SELECT *FROM SWHERE S# NOT IN(SELECT *FROM SCWHERE SC.C#=C.C#))要从语义上分解:(1)选择课程的课程号与课程名,不存在不选这门课的同学。
其中,“不选这门课的同学”可以表示为:SELECT *FROM SWHERE S# NOT IN (SELECT *FROM SC WHERE SC.C#=C.C#) 或者SELECT *FROM SWHERE NOT EXISTS(SELECT *FROM SCWHERE S.S#=C.S#ANDSC.C#=C.C# )(7)检索选修课程包含LIU老师所授课的学生学号。
SELECT DISTINCT S#FROM SCWHERE C# IN(SELECT C#FROM CWHERE TEACHER='LIU'))5.3 设有两个基本表R(A,B,C)和S(D,E,F),试用SQL查询语句表达下列关系代数表达式:(1)πA(R) (2)σB='17'(R) (3)R×S(4))πA,F(σC=D(R×S))(1)SELECT A FROM R(2)SELECT * FROM R WHERE B='17'(3)SELECT A,B,C,D,E,F FROM R,S(4)SELECT A,F FROM R,S WHERE R.C=S.D5.4 3.4 设有两个基本表R(A,B,C)和S(A,B,C)试用SQL查询语句表达下列关系代数表达式:(1)R∪S(2)R∩S(3)R-S (4)πA,B(R)πB,C(S)(1)SELECT A,B,CFROM RUNIONSELECT A,B,CFROM S(2)SELECT A,B,CFROM RINTERSECTSELECT A,B,CFROM S(3)SELECT A,B,CFROM RWHERE NOT EXISTS(SELECT A,B,CFROM SWHERE R.A=S.A AND R.B=S.B AND R.C=S.C)(4)SELECT R.A,R.B,S.CFROM R,SWHERE R.B=S.B5.5 试叙述SQL语言的关系代数特点和元组演算特点。
(P61-62)5.6 试用SQL查询语句表达下列对教学数据库中三个基本表S、SC、C的查询:(1)统计有学生选修的课程门数。
SELECT COUNT(DISTINCT C#) FROM SC(2)求选修C4课程的学生的平均年龄。
SELECT AVG(AGE)FROM SWHERE S# IN(SELECT S#FROM SCWHERE C#='C4')或者,SELECT AVG(AGE)FROM S,SCWHERE S.S#=SC.S# AND C#='004'(3)求LIU老师所授课程的每门课程的学生平均成绩。
SELECT CNAME,AVG(GRADE)FROM SC ,CWHERE SC.C#=C.C# AND TEACHER='LIU'GROUP BY C#(4)统计每门课程的学生选修人数(超过10人的课程才统计)。
要求输出课程号和选修人数,查询结果按人数降序排列,若人数相同,按课程号升序排列。
SELECT DISTINCT C#,COUNT(S#)FROM SCGROUP BY C#HAVING COUNT(S#)>10ORDER BY 2 DESC, C# ASC(5)检索学号比WANG同学大,而年龄比他小的学生姓名。
SELECT X.SNAMEFROM S AS X, S AS YWHERE Y.SNAME='WANG' AND X.S#>Y.S# AND X.AGE<Y.AGE(6)检索姓名以WANG打头的所有学生的姓名和年龄。
SELECT SNAME,AGEFROM SWHERE SNAME LIKE 'WANG%'(7)在SC中检索成绩为空值的学生学号和课程号。
SELECT S#,C#WHERE GRADE IS NULL(8)求年龄大于女同学平均年龄的男学生姓名和年龄。
SELECT SNAME,AGEFROM S AS XWHERE X.SEX='男' AND X.AGE>(SELECT AVG(AGE) FROM S AS Y WHERE Y.SEX='女')(9)求年龄大于所有女同学年龄的男学生姓名和年龄。
SELECT SNAME,AGEFROM S AS XWHERE X.SEX='男' AND X.AGE>ALL (SELECT AGE FROM S AS Y WHERE Y.SEX='女')5.7 试用SQL更新语句表达对教学数据库中三个基本表S、SC、C的各个更新操作:(1)往基本表S中插入一个学生元组(‘S9’,‘WU’,18)。
INSERT INTO S(S#,SNAME,AGE) VALUES('59','WU',18)(2)在基本表S中检索每一门课程成绩都大于等于80分的学生学号、姓名和性别,并把检索到的值送往另一个已存在的基本表STUDENT(S#,SANME,SEX)。
INSERT INTO STUDENT(S#,SNAME,SEX)SELECT S#,SNAME,SEXFROM S WHERE NOT EXISTS(SELECT * FROM SC WHEREGRADE<80 AND S.S#=SC.S#)(3)在基本表SC中删除尚无成绩的选课元组。
DELETE FROM SCWHERE GRADE IS NULL(4)把WANG同学的学习选课和成绩全部删去。
DELETE FROM SCWHERE S# IN(SELECT S#FROM SWHERE SNAME='WANG')(5)把选修MATHS课不及格的成绩全改为空值。
SET GRADE=NULLWHERE GRADE<60 AND C# IN(SELECT C#FROM CWHERE CNAME='MATHS')(6)把低于总平均成绩的女同学成绩提高5%。
UPDATE SCSET GRADE=GRADE*1.05WHERE GRADE<(SELECT AVG(GRADE) FROM SC) AND S# IN (SELECT S# FROM S WHERE SEX='F')(7)在基本表SC中修改C4课程的成绩,若成绩小于等于75分时提高5%,若成绩大于75分时提高4%(用两个UPDATE语句实现)。