数据库习题-部分2

合集下载

数据库系统原理第二章习题

数据库系统原理第二章习题

第2章关系数据库一、选择题1、关于关系模型,下列叙述不正确的是()。

A. 一个关系至少要有一个候选码B。

列的次序可以任意交换C。

行的次序可以任意交换 D. 一个列的值可以来自不同的域2、下列说法正确的是()。

A。

候选码都可以唯一地标识一个元组B。

候选码中只能包含一个属性C. 主属性可以取空值D. 关系的外码不可以取空值3、关系操作中,操作的对象和结果都是()。

A. 记录B。

集合 C. 元组D。

列4、假设存在一张职工表,包含“性别”属性,要求这个属性的值只能取“男”或“女”,这属于().A。

实体完整性B。

参照完整性 C. 用户定义的完整性D。

关系不变性5、有两个关系R(A,B, C)和S(B, C, D),将R和S进行自然连接,得到的结果包含几个列()A. 6 B。

4 C。

5 D. 2二、判断题1、关系模型的一个特点是,实体以及实体之间的联系都可以使用相同的结构类型来表示。

()2、关系模型中,非主属性不可能出现在任何候选码中。

()3、关系模式是对关系的描述,关系是关系模式在某一时刻的状态或内容。

()三、填空题1、在关系模型中,关系操作包括查询、____________、____________和_____________等。

2、关系模型的三类完整性约束是指______________、_______________和_____________。

3、关系模型包括8种查询操作,其中__________、_________、并、________和笛卡儿积是5种基本操作,其他操作可以用基本操作定义和导出。

4、职工(职工号,姓名,年龄,部门号)和部门(部门号,部门名称)存在引用关系,其中________________是参照关系,____________是外码。

四、综合题假设有一个数据库包含以下关系模式:Teacher(Tno, Tname, Tage,Tsex)Department(Dno, Dname,Tno)Work(Tno,Dno,Year, Salary)教师表Teacher由教师代码Tno、教师名字Tname、教师年龄Tage、教师性别Tsex组成. 系表Department由系代码Dno、系名Dname、系主任代码Tno组成工作表Work由教师代码Tno、系代码Dno、入职年份Year、工资Salary组成使用关系代数表示每个查询(1)列出工资超过5000的教师的不同年龄;(2)查找不在计算机系工作的教师代码;(3)系主任T1管辖范围内的所有教师姓名。

数据库第二章关系代数习题

数据库第二章关系代数习题

数据库第二章关系代数习题编辑整理:尊敬的读者朋友们:这里是精品文档编辑中心,本文档内容是由我和我的同事精心编辑整理后发布的,发布之前我们对文中内容进行仔细校对,但是难免会有疏漏的地方,但是任然希望(数据库第二章关系代数习题)的内容能够给您的工作和学习带来便利。

同时也真诚的希望收到您的建议和反馈,这将是我们进步的源泉,前进的动力。

本文可编辑可修改,如果觉得对您有帮助请收藏以便随时查阅,最后祝您生活愉快业绩进步,以下为数据库第二章关系代数习题的全部内容。

1.设有如图所示的关系S、SC和C,试用关系代数表达式表示下列查询语句:SC SC(1)检索”程军"老师所授课的课程号(C#)和课程名(CNAME)。

(2) 检索年龄大于21的男学生学号(S#)和姓名(SNAME)。

(3) 检索至少选修"程军”老师所授全部课程的学生姓名(SNAME)。

(4)检索"李强”同学不学课程的课程号(C#)。

(5)检索至少选修两门课程的课程号(S#)。

(6) 检索全部学生都选修的课程的课程号(C#)和课程名(CNAME)。

(7) 检索选修课程包含"程军”老师所授课程之一的学生学号(S#)。

(8) 检索选修课程号为k1和k5的学生学号(S#)。

(9)检索选修全部课程的学生姓名(SNAME)。

(10)检索选修课程包含学号为2的学生所选修课程的学生学号(S#)。

(11)检索选修课程名为”C语言”的学生学号(S#)和姓名(SNAME).(12)检索没有一门课程成绩不及格的学生学号,姓名。

答:本题各个查询语句对应的关系代数表达式表示如下:(1) ΠC#,CNAME(σTEACHER =’程军’(C))(2)ΠS#,SNAME(σAGE〉21^SEX =’男'(S))(3)ΠSNAME(S(ΠS#,C#(SC)÷ΠC#(σTEACHER =’程军’(C))))(4)ΠC#(C)-ΠC#(σSNAME ='李强’(S)∞ SC)(5) ΠS#(σ1=4^2≠5(SC×SC))(6) ΠC#,CNAME(C∞ (ΠS#,C#(SC)÷ΠS#(S)))(7)ΠS#(SC∞ΠC#(σTEACHER ='程军’(C)))(8)ΠS#,C#(SC)÷ΠC#(σC#='K1’VC#=’K5' (C))(9)ΠSNAME(S∞ (ΠS#,C#(SC)÷ΠC#(C)))(10)ΠS#,C#(SC)÷ΠC#(σC#='2’(SC))(11) ΠS#,SNAME(S∞ΠS#(SC∞ (σCNAME =’C语言’(C))))(12)П学号,姓名(学生)-П学号,姓名(σ分数<60(学生∞学习))。

数据库第2章关系数据库练习题

数据库第2章关系数据库练习题
π学号,姓名( (π学号,课程号(选课)÷π课程号(σ学号= ‘98002’(选课)) ) ⋈ 学生 )
习题


学生关系S (Sno, Sname, Ssex, Sage, Class)
课程关系C (Cno, Cname, DeptName) 学生选课关系R (Sno, Cno, Grade) R)
1.检索所有学生学号、姓名、课程号、成绩 sno,sname,cno,Grade ( S sno,sname ( Cno=‘C02’( S
2.检索学习课程号为C02的学生学号与姓名
R))
sno,sname ( S
sno,sname (S)
Cno=‘C02’ (R)) 优化
sno (Cno=‘C02’ (R)) 再优化
B 2 2 5 D 3 6
C 3 3 6 E 1 2
D 3 6 6
E 1 2 2
R
C=D
S
课堂练习
R
A a b B l n B f
S
C g D h
l
n
x
p
y
x

R×S R R S
R. B S. B


S
R×S
A
a a a b b b
R.B
l l l n n n
S.B
f l n f l n
C
g x p g x p

难题
Sno(2 5 ∧1=4 ( R R) ) 优化: Sno(2 5 ( R
R.sno= R.sno
R) name, Ssex, Sage, Class) 课程关系C(Cno, Cname, DeptName) 学生选课关系R(Sno, Cno, Grade)

数据库系统基础教程(第二版)课后习题答案2

数据库系统基础教程(第二版)课后习题答案2

Database Systems: The Complete BookSolutions for Chapter 2Solutions for Section 2.1Exercise 2.1.1The E/R Diagram.Exercise 2.1.8(a)The E/R DiagramKobvxybzSolutions for Section 2.2Exercise 2.2.1The Addresses entity set is nothing but a single address, so we would prefer to make address an attribute of Customers. Were the bank to record several addresses for a customer, then it might make sense to have an Addresses entity set and make Lives-at a many-many relationship.The Acct-Sets entity set is useless. Each customer has a unique account set containing his or her accounts. However, relating customers directly to their accounts in a many-many relationship conveys the same information and eliminates the account-set concept altogether.Solutions for Section 2.3Exercise 2.3.1(a)Keys ssNo and number are appropriate for Customers and Accounts, respectively. Also, we think it does not make sense for an account to be related to zero customers, so we should round the edge connecting Owns to Customers. It does not seem inappropriate to have a customer with 0 accounts;they might be a borrower, for example, so we put no constraint on the connection from Owns to Accounts. Here is the The E/R Diagram,showing underlined keys andthe numerocity constraint.Exercise 2.3.2(b)If R is many-one from E1 to E2, then two tuples (e1,e2) and (f1,f2) of the relationship set for R must be the same if they agree on the key attributes for E1. To see why, surely e1 and f1 are the same. Because R is many-one from E1 to E2, e2 and f2 must also be the same. Thus, the pairs are the same.Solutions for Section 2.4Exercise 2.4.1Here is the The E/R Diagram.We have omitted attributes other than our choice for the key attributes of Students and Courses. Also omitted are names for the relationships. Attribute grade is not part of the key for Enrollments. The key for Enrollements is studID from Students and dept and number from Courses.Exercise 2.4.4bHere is the The E/R Diagram Again, we have omitted relationship names and attributes other than our choice for the key attributes. The key for Leagues is its own name; this entity set is not weak. The key for Teams is its own name plus the name of the league of which the team is a part, e.g., (Rangers, MLB) or (Rangers, NHL). The key for Players consists of the player's number and the key for the team on which he or she plays. Since the latter key is itself a pair consisting of team and league names, the key for players is the triple (number, teamName, leagueName). e.g., JeffGarcia is (5, 49ers, NFL).Database Systems: The Complete BookSolutions for Chapter 3Solutions for Section 3.1Exercise 3.1.2(a)We can order the three tuples in any of 3! = 6 ways. Also, the columns can be ordered in any of 3! = 6 ways. Thus, the number of presentations is 6*6 = 36.Solutions for Section 3.2Exercise 3.2.1Customers(ssNo, name, address, phone)Flights(number, day, aircraft)Bookings(ssNo, number, day, row, seat)Being a weak entity set, Bookings' relation has the keys for Customers and Flights and Bookings' own attributes.Notice that the relations obtained from the toCust and toFlt relationships are unnecessary. They are:toCust(ssNo, ssNo1, number, day)toFlt(ssNo, number, day, number1, day1)That is, for toCust, the key of Customers is paired with the key for Bookings. Since both include ssNo, this attribute is repeated with two different names, ssNo and ssNo1. A similar situation exists for toFlt.Exercise 3.2.3Ships(name, yearLaunched)SisterOf(name, sisterName)Solutions for Section 3.3Exercise 3.3.1Since Courses is weak, its key is number and the name of its department. We do not have arelation for GivenBy. In part (a), there is a relation for Courses and a relation for LabCourses that has only the key and the computer-allocation attribute. It looks like:Depts(name, chair)Courses(number, deptName, room)LabCourses(number, deptName, allocation)For part (b), LabCourses gets all the attributes of Courses, as:Depts(name, chair)Courses(number, deptName, room)LabCourses(number, deptName, room, allocation)And for (c), Courses and LabCourses are combined, as:Depts(name, chair)Courses(number, deptName, room, allocation)Exercise 3.3.4(a)There is one relation for each entity set, so the number of relations is e. The relation for the root entity set has a attributes, while the other relations, which must include the key attributes, have a+k attributes.Solutions for Section 3.4Exercise 3.4.2Surely ID is a key by itself. However, we think that the attributes x, y, and z together form another key. The reason is that at no time can two molecules occupy the same point.Exercise 3.4.4The key attributes are indicated by capitalization in the schema below:Customers(SSNO, name, address, phone)Flights(NUMBER, DAY, aircraft)Bookings(SSNO, NUMBER, DAY, row, seat)Exercise 3.4.6(a)The superkeys are any subset that contains A1. Thus, there are 2^{n-1} such subsets, since each of the n-1 attributes A2 through An may independently be chosen in or out.Solutions for Section 3.5Exercise 3.5.1(a)We could try inference rules to deduce new dependencies until we are satisfied we have them all.A more systematic way is to consider the closures of all 15 nonempty sets of attributes.For the single attributes we have A+ = A, B+ = B, C+ = ACD, and D+ = AD. Thus, the only new dependency we get with a single attribute on the left is C->A.Now consider pairs of attributes:AB+ = ABCD, so we get new dependency AB->D. AC+ = ACD, and AC->D is nontrivial. AD+ = AD, so nothing new. BC+ = ABCD, so we get BC->A, and BC->D. BD+ = ABCD, giving usBD->A and BD->C. CD+ = ACD, giving CD->A.For the triples of attributes, ACD+ = ACD, but the closures of the other sets are each ABCD. Thus, we get new dependencies ABC->D, ABD->C, and BCD->A.Since ABCD+ = ABCD, we get no new dependencies.The collection of 11 new dependencies mentioned above is: C->A, AB->D, AC->D, BC->A, BC->D, BD->A, BD->C, CD->A, ABC->D, ABD->C, and BCD->A.Exercise 3.5.1(b)From the analysis of closures above, we find that AB, BC, and BD are keys. All other sets either do not have ABCD as the closure or contain one of these three sets.Exercise 3.5.1(c)The superkeys are all those that contain one of those three keys. That is, a superkey that is not a key must contain B and more than one of A, C, and D. Thus, the (proper) superkeys are ABC, ABD, BCD, and ABCD.Exercise 3.5.3(a)We must compute the closure of A1A2...AnC. Since A1A2...An->B is a dependency, surely B is in this set, proving A1A2...AnC->B.Exercise 3.5.4(a)Consider the relationThis relation satisfies A->B but does not satisfy B->A.Exercise 3.5.8(a)If all sets of attributes are closed, then there cannot be any nontrivial functional dependenc ies. For suppose A1A2...An->B is a nontrivial dependency. Then A1A2...An+ contains B and thus A1A2...An is not closed.Exercise 3.5.10(a)We need to compute the closures of all subsets of {ABC}, although there is no need to think about the empty set or the set of all three attributes. Here are the calculations for the remaining six sets: A+ = AB+ = BC+ = ACEAB+ = ABCDEAC+ = ACEBC+ = ABCDEWe ignore D and E, so a basis for the resulting functional dependencies for ABC are: C->A and AB->C. Note that BC->A is true, but follows logically from C->A, and therefore may be omitted from our list.Solutions for Section 3.6Exercise 3.6.1(a)In the solution to Exercise 3.5.1 we found that there are 14 nontrivial dependencies, including the three given ones and 11 derived dependencies. These are: C->A, C->D, D->A, AB->D, AB-> C, AC->D, BC->A, BC->D, BD->A, BD->C, CD->A, ABC->D, ABD->C, and BCD->A.We also learned that the three keys were AB, BC, and BD. Thus, any dependency above that does not have one of these pairs on the left is a BCNF violation. These are: C->A, C->D, D->A, AC->D, and CD->A.One choice is to decompose using C->D. That gives us ABC and CD as decomposed relations. CD is surely in BCNF, since any two-attribute relation is. ABC is not in BCNF, since AB and BC are its only keys, but C->A is a dependency that holds in ABCD and therefore holds in ABC. We must further decompose ABC into AC and BC. Thus, the three relations of the decomposition are AC, BC, and CD.Since all attributes are in at least one key of ABCD, that relation is already in 3NF, and no decomposition is necessary.Exercise 3.6.1(b)(Revised 1/19/02) The only key is AB. Thus, B->C and B->D are both BCNF violations. The derived FD's BD->C and BC->D are also BCNF violations. However, any other nontrivial, derived FD will have A and B on the left, and therefore will contain a key.One possible BCNF decomposition is AB and BCD. It is obtained starting with any of the four violations mentioned above. AB is the only key for AB, and B is the only key for BCD.Since there is only one key for ABCD, the 3NF violations are the same, and so is the decomposition.Solutions for Section 3.7Exercise 3.7.1Since A->->B, and all the tuples have the same value for attribute A, we can pair the B-value from any tuple with the value of the remaining attribute C from any other tuple. Thus, we know that R must have at least the nine tuples of the form (a,b,c), where b is any of b1, b2, or b3, and c is any of c1, c2, or c3. That is, we can derive, using the definition of a multivalued dependency, that each of the tuples (a,b1,c2), (a,b1,c3), (a,b2,c1), (a,b2,c3), (a,b3,c1), and (a,b3,c2) are also in R.Exercise 3.7.2(a)First, people have unique Social Security numbers and unique birthdates. Thus, we expect the functional dependencies ssNo->name and ssNo->birthdate hold. The same applies to children, so we expect childSSNo->childname and childSSNo->childBirthdate. Finally, an automobile has a unique brand, so we expect autoSerialNo->autoMake.There are two multivalued dependencies that do not follow from these functional dependencies. First, the information about one child of a person is independent of other information about that person. That is, if a person with social security number s has a tuple with cn,cs,cb, then if there isany other tuple t for the same person, there will also be another tuple that agrees with t except that it has cn,cs,cb in its components for the child name, Social Security number, and birthdate. That is the multivalued dependencyssNo->->childSSNo childName childBirthdateSimilarly, an automobile serial number and make are independent of any of the other attributes, so we expect the multivalued dependencyssNo->->autoSerialNo autoMakeThe dependencies are summarized below:ssNo -> name birthdatechildSSNo -> childName childBirthdateautoSerialNo -> autoMakessNo ->-> childSSNo childName childBirthdatessNo ->-> autoSerialNo autoMakeExercise 3.7.2(b)We suggest the relation schemas{ssNo, name, birthdate}{ssNo, childSSNo}{childSSNo, childName childBirthdate}{ssNo, autoSerialNo}{autoSerialNo, autoMake}An initial decomposition based on the two multivalued dependencies would give us {ssNo, name, birthDate}{ssNo, childSSNo, childName, childBirthdate}{ssNo, autoSerialNo, autoMake}Functional dependencies force us to decompose the second and third of these.Exercise 3.7.3(a)Since there are no functional dependencies, the only key is all four attributes, ABCD. Thus, each of the nontrvial multivalued dependencies A->->B and A->->C violate 4NF. We must separate out the attributes of these dependencies, first decomposing into AB and ACD, and then decomposing the latter into AC and AD because A->->C is still a 4NF violation for ACD. The final set of relations are AB, AC, and AD.Exercise 3.7.7(a)Let W be the set of attributes not in X, Y, or Z. Consider two tuples xyzw and xy'z'w' in the relation R in question. Because X ->-> Y, we can swap the y's, so xy'zw and xyz'w' are in R. Because X ->-> Z, we can take the pair of tuples xyzw and xyz'w' and swap Z's to get xyz'w and xyzw'. Similarly, we can take the pair xy'z'w' and xy'zw and swap Z's to get xy'zw' and xy'z'w.In conclusion, we started with tuples xyzw and xy'z'w' and showed that xyzw' and xy'z'w must also be in the relation. That is exactly the statement of the MVD X ->-> Y-union-Z. Note that the above statements all make sense even if there are attributes in common among X, Y, and Z.Exercise 3.7.8(a)Consider a relation R with schema ABCD and the instance with four tuples abcd, abcd', ab'c'd, and ab'c'd'. This instance satisfies the MVD A->-> BC. However, it does not satisfy A->-> B. For example, if it did satisfy A->-> B, then because the instance contains the tuples abcd and ab'c'd, we would expect it to contain abc'd and ab'cd, neither of which is in the instance.Database Systems: The Complete BookSolutions for Chapter 4Solutions for Section 4.2Exercise 4.2.1class Customer {attribute string name;attribute string addr;attribute string phone;attribute integer ssNo;relationship Set<Account> ownsAcctsinverse Account::ownedBy;}class Account {attribute integer number;attribute string type;attribute real balance;relationship Set<Customer> ownedByinverse Customer::ownsAccts}Exercise 4.2.4class Person {attribute string name;relationship Person motherOfinverse Person::childrenOfFemalerelationship Person fatherOfinverse Person::childrenOfMalerelationship Set<Person> childreninverse Person::parentsOfrelationship Set<Person> childrenOfFemaleinverse Person::motherOfrelationship Set<Person> childrenOfMaleinverse Person::fatherOfrelationship Set<Person> parentsOfinverse Person::children}Notice that there are six different relationships here. For example, the inverse of the relationship that connects a person to their (unique) mother is a relationship that connects a mother (i.e., a female person) to the set of her children. That relationship, which we call childrenOfFemale, is different from the children relationship, which connects anyone -- male or female -- to their children.Exercise 4.2.7A relationship R is its own inverse if and only if for every pair (a,b) in R, the pair (b,a) is also in R. In the terminology of set theory, the relation R is ``symmetric.''Solutions for Section 4.3Exercise 4.3.1We think that Social Security number should me the key for Customer, and account number should be the key for Account. Here is the ODL solution with key and extent declarations.class Customer(extent Customers key ssNo){attribute string name;attribute string addr;attribute string phone;attribute integer ssNo;relationship Set<Account> ownsAcctsinverse Account::ownedBy;}class Account(extent Accounts key number){attribute integer number;attribute string type;attribute real balance;relationship Set<Customer> ownedByinverse Customer::ownsAccts}Solutions for Section 4.4Exercise 4.4.1(a)Since the relationship between customers and accounts is many-many, we should create a separate relation from that relationship-pair.Customers(ssNo, name, address, phone)Accounts(number, type, balance)CustAcct(ssNo, number)Exercise 4.4.1(d)Ther is only one attribute, but three pairs of relationships from Person to itself. Since motherOf and fatherOf are many-one, we can store their inverses in the relation for Person. That is, for each person, childrenOfMale and childrenOfFemale will indicate that persons's father and mother. The children relationship is many-many, and requires its own relation. This relation actually turns out to be redundant, in the sense that its tuples can be deduced from the relationships stored with Person. The schema:Persons(name, childrenOfFemale, childrenOfMale)Parent-Child(parent, child)Exercise 4.4.4Y ou get a schema like:Studios(name, address, ownedMovie)Since name -> address is the only FD, the key is {name, ownedMovie}, and the FD has a left side that is not a superkey.Exercise 4.4.5(a,b,c)(a) Struct Card { string rank, string suit };(b) class Hand {attribute Set theHand;};For part (c) we have:Hands(handId, rank, suit)Notice that the class Hand has no key, so we need to create one: handID. Each hand has, in the relation Hands, one tuple for each card in the hand.Exercise 4.4.5(e)Struct PlayerHand { string Player, Hand theHand };class Deal {attribute Set theDeal;}Alternatively, PlayerHand can be defined directly within the declaration of attribute theDeal. Exercise 4.4.5(h)Since keys for Hand and Deal are lacking, a mechanical way to design the database schema is to have one relation connecting deals and player-hand pairs, and another to specify the contents of hands. That is:Deals(dealID, player, handID)Hands(handID, rank, suit)However, if we think about it, we can get rid of handID and connect the deal and the player directly to the player's cards, as:Deals(dealID, player, rank, suit)Exercise 4.4.5(i)First, card is really a pair consisting of a suit and a rank, so we need two attributes in a relation schema to represent cards. However, much more important is the fact that the proposed schema does not distinguish which card is in which hand. Thus, we need another attribute that indicates which hand within the deal a card belongs to, something like:Deals(dealID, handID, rank, suit)Exercise 4.4.6(c)Attribute b is really a bag of (f,g) pairs. Thus, associated with each a-value will be zero or more (f,g) pairs, each of which can occur several times. We shall use an attribute count to indicate the number of occurrences, although if relations allow duplicate tuples we could simply allow duplicate (a,f,g) triples in the relation. The proposed schema is:C(a, f, g, count)Solutions for Section 4.5Exercise 4.5.1(b)Studios(name, address, movies{(title, year, inColor, length,stars{(name, address, birthdate)})})Since the information about a star is repeated once for each of their movies, there is redundancy. To eliminate it, we have to use a separate relation for stars and use pointers from studios. That is: Stars(name, address, birthdate)Studios(name, address, movies{(title, year, inColor, length,stars{*Stars})})Since each movie is owned by one studio, the information about a movie appears in only one tuple of Studios, and there is no redundancy.Exercise 4.5.2Customers(name, address, phone, ssNo, accts{*Accounts})Accounts(number, type, balance, owners{*Customers})Solutions for Section 4.6Exercise 4.6.1(a)We need to add new nodes labeled George Lucas and Gary Kurtz. Then, from the node sw (which represents the movie Star Wars), we add arcs to these two new nodes, labeled direc tedBy and producedBy, respectively.Exercise 4.6.2Create nodes for each account and each customer. From each customer node is an arc to a node representing the attributes of the customer, e.g., an arc labeled name to the customer's name. Likewise, there is an arc from each account node to each attribute of that account, e.g., an arc labeled balance to the value of the balance.To represent ownership of accounts by customers, we place an arc labeled owns from each customer node to the node of each account that customer holds (possibly jointly). Also, we placean arc labeled ownedBy from each account node to the customer node for each owner of that account.Exercise 4.6.5In the semistructured model, nodes represent data elements, i.e., entities rather than entity sets. In the E/R model, nodes of all types represent schema elements, and the data is not represented at all. Solutions for Section 4.7Exercise 4.7.1(a)<STARS-MOVIES><STAR starId = "cf" starredIn = "sw, esb, rj"><NAME>Carrie Fisher</NAME><ADDRESS><STREET>123 Maple St.</STREET><CITY>Hollywood</CITY></ADDRESS><ADDRESS><STREET>5 Locust Ln.</STREET><CITY>Malibu</CITY></ADDRESS></STAR><STAR starId = "mh" starredIn = "sw, esb, rj"><NAME>Mark Hamill</NAME><ADDRESS><STREET>456 Oak Rd.<STREET><CITY>Brentwood</CITY></ADDRESS></STAR><STAR starId = "hf" starredIn = "sw, esb, rj, wit"><NAME>Harrison Ford</NAME><ADDRESS><STREET>whatever</STREET><CITY>whatever</CITY></ADDRESS></STAR><MOVIE movieId = "sw" starsOf = "cf, mh"><TITLE>Star Wars</TITLE><YEAR>1977</YEAR></MOVIE><MOVIE movieId = "esb" starsOf = "cf, mh"><TITLE>Empire Strikes Back</TITLE><YEAR>1980</YEAR></MOVIE><MOVIE movieId = "rj" starsOf = "cf, mh"><TITLE>Return of the Jedi</TITLE><YEAR>1983</YEAR></MOVIE><MOVIE movieID = "wit" starsOf = "hf"><TITLE>Witness</TITLE><YEAR>1985</YEAR></MOVIE></STARS-MOVIES>Exercise 4.7.2<!DOCTYPE Bank [<!ELEMENT BANK (CUSTOMER* ACCOUNT*)><!ELEMENT CUSTOMER (NAME, ADDRESS, PHONE, SSNO)> <!A TTLIST CUSTOMERcustId IDowns IDREFS><!ELEMENT NAME (#PCDA TA)><!ELEMENT ADDRESS (#PCDA TA)><!ELEMENT PHONE (#PCDA TA)><!ELEMENT SSNO (#PCDA TA)><!ELEMENT ACCOUNT (NUMBER, TYPE, BALANCE)><!A TTLIST ACCOUNTacctId IDownedBy IDREFS><!ELEMENT NUMBER (#PCDA TA)><!ELEMENT TYPE (#PCDA TA)><!ELEMENT BALANCE (#PCDA TA)>]>Database Systems: The CompleteBookSolutions for Chapter 5Solutions for Section 5.2Exercise 5.2.1(a)PI_model( SIGMA_{speed >= 1000} ) (PC)Exercise 5.2.1(f)The trick is to theta-join PC with itself on the condition that the hard disk sizes are equal. That gives us tuples that have two PC model numbers with the same value of hd. However, these two PC's could in fact be the same, so we must also require in the theta-join that the model numbers be unequal. Finally, we want the hard disk sizes, so we project onto hd.The expression is easiest to see if we write it using some temporary values. We start by renaming PC twice so we can talk about two occurrences of the same attributes.R1 = RHO_{PC1} (PC)R2 = RHO_{PC2} (PC)R3 = R1 JOIN_{PC1.hd = PC2.hd AND PC1.model <> PC2.model} R2R4 = PI_{PC1.hd} (R3)Exercise 5.2.1(h)First, we find R1, the model-speed pairs from both PC and Laptop. Then, we find from R1 those computers that are ``fast,'' at least 133Mh. At the same time, we join R1 with Product to connect model numbers to their manufacturers and we project out the speed to get R2. Then we join R2 with itself (after renaming) to find pairs of different models by the same maker. Finally, we get our answer, R5, by projecting onto one of the maker attributes. A sequence of steps giving the desired expression is: R1 = PI_{model,speed} (PC) UNION PI_{model,speed} (Laptop)R2 = PI_{maker,model} (SIGMA_{speed>=700} (R1) JOIN Product)R3 = RHO_{T(maker2, model2)} (R2)R4 = R2 JOIN_{maker = maker2 AND model <> model2} (R3)R5 = PI_{maker} (R4)Exercise 5.2.2Here are figures for the expression trees of Exercise 5.2.1 Part (a)Part (f)Part (h). Note that the third figure is not really a tree, since it uses a common subexpression. We could duplicate the nodes to make it a tree, but using common subexpressions is a valuable form of query optimization. One of the benefits one gets from constructing ``trees'' for queries is the ability to combine nodes that represent common subexpressions.Exercise 5.2.7The relation that results from the natural join has only one attribute from each pair of equated attributes. The theta-join has attributes for both, and their columns are identical.Exercise 5.2.9(a)If all the tuples of R and S are different, then the union has n+m tuples, and this number is the maximum possible.The minimum number of tuples that can appear in the result occurs if every tuple of one relation also appears in the other. Surely the union has at least as many tuples as the larger of R and that is, max(n,m) tuples. However, it is possible for every tuple of the smaller to appear in the other, so it is possible that there are as few as max(n,m) tuples in the union.Exercise 5.2.10In the following we use the name of a relation both as its instance (set of tuples) and as its schema (set of attributes). The context determines uniquely which is meant.PI_R(R JOIN S) Note, however, that this expression works only for sets; it does not preserve the multipicity of tuples in R. The next two expressions work for bags.R JOIN DELTA(PI_{R INTERSECT S}(S)) In this expression, each projection of a tuple from S onto the attributes that are also in R appears exactly once in the second argument of the join, so it preserves multiplicity of tuples in R, except for those thatdo not join with S, which disappear. The DELTA operator removes duplicates, as described in Section 5.4.R - [R - PI_R(R JOIN S)] Here, the strategy is to find the dangling tuples of R and remove them.Solutions for Section 5.3Exercise 5.3.1As a bag, the value is {700, 1500, 866, 866, 1000, 1300, 1400, 700, 1200, 750, 1100, 350, 733}. The order is unimportant, of course. The average is 959.As a set, the value is {700, 1500, 866, 1000, 1300, 1400, 1200, 750, 1100, 350, 733}, and the average is 967. H3>Exercise 5.3.4(a)As sets, an element x is in the left-side expression(R UNION S) UNION Tif and only if it is in at least one of R, S, and T. Likewise, it is in the right-side expressionR UNION (S UNION T)under exactly the same conditions. Thus, the two expressions have exactly the same members, and the sets are equal.As bags, an element x is in the left-side expression as many times as the sum of the number of times it is in R, S, and T. The same holds for the right side. Thus, as bags the expressions also have the same value.Exercise 5.3.4(h)As sets, element x is in the left sideR UNION (S INTERSECT T)if and only if x is either in R or in both S and T. Element x is in the right side(R UNION S) INTERSECT (R UNION T)if and only if it is in both R UNION S and R UNION T. If x is in R, then it is in both unions. If x is in both S and T, then it is in both union. However, if x is neither in R nor in both of S and T, then it cannot be in both unions. For example, suppose x is not in R and not in S. Then x is not in R UNION S. Thus, the statement of when x is in the right side is exactly the same as when it is in the left side: x is either in R or in both of S and T.Now, consider the expression for bags. Element x is in the left side the sum of the number of times it is in R plus the smaller of the number of times x is in S and the number of times x is in T. Likewise, the number of times x is in the right side is the smaller ofThe sum of the number of times x is in R and in S.The sum of the number of times x is in R and in T.A moment's reflection tells us that this minimum is the sum of the number of times x is in R plus the smaller of the number of times x is in S and in T, exactly as for the left side.Exercise 5.3.5(a)For sets, we observe that element x is in the left side(R INTERSECT S) - T。

南京邮电大学数据库系统课后习题答案2

南京邮电大学数据库系统课后习题答案2

4.30 设有关系模式R(ABCD),其上的FD集为 ② F={AB→C,C→A,C→D}, ρ={ACD, BC} ⑤ F={A→B,B→C,C→D}, ρ={AB,AD,CD}
解② :(1)R的关键码 AB、BC (2) ρ中有R1(ACD), R2(BC)
R1∩R2=C, R1-R2=AD, 由F经合并性推理得: C→AD,ρ无损
F2={职工编号→部门名,部门名→部门经理} Key2: 职工编号, R2无部分依赖,达2NF
(3)分解成3NF R1无传递依赖,达3NF R2中:职工编号→部门经理 是传递依赖关系
将R2分解为3NF模式集 R21(职工编号,部门名) R22(部门名,部门经理 )
ρ={(职工编号,日期,日营业额), (职工编号,部门名),(部门名,部门经理)}
R2(CNO, TNAME, TADDR) } F2={CNO→TNAME,TNAME→TADDR}, KEY=(CNO) ρ中R1、R2的所有属性都是原子的,且没有非 主属性对候选键的部分函数依赖,达到2NF;
(3) 试把R分解成3NF模式集,并说明理由;
ρ={ R1(SNO, CNO, GRADE) , F1={{SNO,CNO}→GRADE}, KEY=(SNO, CNO) R21(CNO, TNAME) , F21={CNO→TNAME}, KEY=(CNO)
F={ { SNO,CNO }→GRADE , CNO→TNAME , TNAME→TADDR }
KEY={ SNO,CNO }
(2) 试把R分解成2NF模式集,并说明理由;
ρ={ R1(SNO, CNO, GRADE) , F1={{ SNO,CNO }→GRADE}, KEY=(SNO, CNO)

数据库原理复习练习题含答案(二)

数据库原理复习练习题含答案(二)

数据库原理复习练习题含答案泰山学院信息科学技术学院计算机科学与技术专业数据库系统概论本科试卷(试卷共6页,答题时间120分钟)题号一二三四五总分统分人复核人得分得分阅卷人一、选择题(每小题2分,共20 分。

请将答案填在下面的表格内)题号 1 2 3 4 5 6 78910答案1、数据库管理系统是管理控制数据库的主要软件,简称()。

A、DBB、DBMSC、DBSD、DBT2、反映现实世界中实体及实体间联系的信息模型是()。

A.关系模型B.层次模型C.网状模型D.E-R模型3、关系数据模型的三个组成部分中,不包括()。

A. 数据结构B. 数据操作C.数据控制D. 完整性规则4、下列语句中,()不属于SQL中DML的语句A.SELECTB.CREATEC.INSERTD.DELETE5、一个关系模式属于3NF,是指( )。

A.每个非主属性都不传递依赖于主键B.主键唯一标识关系中的元组C.关系中的元组不能重复D.每个属性都是不可分解的6、设有关系R(A,B,C)R上的函数依赖集F={A→B,A→C}。

则关系R属于( )A.1NFB.2NFC.3NFD.BCNF7、DBMS在运行过程中建立的日志文件,主要用于对数据库的()A.安全性控制 B. 并发调度控制C.数据库恢复 D. 完整性控制8、设关系模式R是3NF模式,那么下列说明不正确的是()。

A.R必是2NF模式 B.R必定不是BCNFC.R可能不是BCNF D.R必定是1NF模式9、.若事务T1已经给数据Q加上了S锁,则事务T2对Q可以()A. 加S锁B. 加X锁C. 加S锁,或X锁D.不能再给Q加任何锁10、SQL提供的触发器机制是对数据库系统采取的一种()措施。

A、完整性控制B、安全性控制C、数据库恢复D、事务并发控制得分阅卷人二、填空题(每题2分,共20分)1、数据模型的三个组成部分是___________ 、数据操作和完整性约束规则。

2、事务故障包括事物内部故障、_________、介质故障、计算机病毒。

数据库技术复习题2 操作题

数据库技术复习题2 操作题

数据库技术试题三、操作题1. 设有关系数据库:职工关系EMPLOYEE (职工号,职工名,街道,城市)工作关系WORKS (职工号,公司号,工资)公司关系COMPANY (公司号,公司名,城市)假设职工可在多个公司兼职,请用关系代数表达式写出至少在公司号为‘C2’和‘C5’公司兼职的职工的职工号。

2. 设有关系数据库:职工关系EMPLOYEE (职工号,职工名,街道,城市)工作关系WORKS (职工号,公司号,工资)公司关系COMPANY (公司号,公司名,城市)试用SQL语句写出下列操作:将所有在“联华公司”工作的职工加薪5﹪。

3. 图书出版管理数据库中有两个基本表:图书 (书号,书名,作者编号,出版社,出版日期)作者 (作者编号,作者名,年龄,地址)试用SQL语句写出下列查询:查询年龄低于作者平均年龄的所有作者的作者名、书名和出版社。

4. 设有商店和顾客两个实体,“商店”有属性商店编号、商店名、地址、电话,“顾客”有属性顾客编号、姓名、地址、年龄、性别。

假设一个商店有多个顾客购物,一个顾客可以到多个商店购物,顾客每次去商店购物有一个消费金额和日期,而且规定每个顾客在每个商店里每天最多消费一次。

试画出ER图,并注明属性和联系类型。

5. 学校有多名学生,财务处每年要收一次学费。

为财务处收学费工作设计一个数据库,包括两个关系:学生 (学号,姓名,专业,入学日期)收费 (学年,学号,学费,书费,总金额)假设规定属性的类型:学费、书费、总金额为数值型数据;学号、姓名、学年、专业为字符型数据;入学日期为日期型数据。

列的宽度自定义。

试用SQL语句定义上述表的结构。

(定义中应包括主键子句和外键子句)6. 用SQL语言定义(1) 学生关系S,包括学号SNo、姓名SN、年龄SA、系别SD;(2) 课程关系C,包括课程号CNo、课程名CN、学分CC;(3) 学生选课关系SC,包括SNo、CNo和成绩G。

注意:说明主键码和外键码(如果有的话)。

(完整版)数据库第二章关系代数习题

(完整版)数据库第二章关系代数习题

1.设有如图所示的关系S、SC和C,试用关系代数表达式表示下列查询语句:S C SCS# SNAME AGE SEX1 李强23 男2 刘丽22 女5 张友22 男C# CNAME TEACHERk1 C语言王华k5 数据库原理程军k8 编译原理程军S# C# GRADE1 k1 832 k1 855 k1 922 k5 905 k5 845 k8 80(1) 检索”程军”老师所授课的课程号(C#)和课程名(CNAME)。

(2) 检索年龄大于21的男学生学号(S#)和姓名(SNAME)。

(3) 检索至少选修”程军”老师所授全部课程的学生姓名(SNAME)。

(4) 检索”李强”同学不学课程的课程号(C#)。

(5) 检索至少选修两门课程的课程号(S#)。

(6) 检索全部学生都选修的课程的课程号(C#)和课程名(CNAME)。

(7) 检索选修课程包含”程军”老师所授课程之一的学生学号(S#)。

(8) 检索选修课程号为k1和k5的学生学号(S#)。

(9) 检索选修全部课程的学生姓名(SNAME)。

(10) 检索选修课程包含学号为2的学生所选修课程的学生学号(S#)。

(11) 检索选修课程名为”C语言”的学生学号(S#)和姓名(SNAME)。

(12)检索没有一门课程成绩不及格的学生学号,姓名。

答:本题各个查询语句对应的关系代数表达式表示如下:(1) ΠC#,CNAME(σTEACHER ='程军'(C))(2) ΠS#,SNAME(σAGE>21^SEX ='男'(S))(3) ΠSNAME(S(ΠS#,C#(SC)÷ΠC#(σTEACHER ='程军'(C))))(4) ΠC#(C)-ΠC#(σSNAME ='李强'(S)∞SC)(5) ΠS# (σ1=4^2≠5 (S C×SC))(6) ΠC#,CNAME(C∞(ΠS#,C#(SC)÷ΠS#(S)))(7) ΠS# (SC∞ΠC# (σTEACHER ='程军'(C)))(8) ΠS#,C#(SC)÷ΠC#(σC#=’K1’VC#=’K5’ (C))(9) ΠSNAME(S∞(ΠS#,C#(SC)÷ΠC#(C)))(10) ΠS#,C#(SC)÷ΠC#(σC#=’2’ (S C))(11) ΠS#,SNAME(S∞ΠS#(SC∞(σCNAME ='C语言'(C))))(12)П学号,姓名(学生)-П学号,姓名(σ分数<60(学生∞学习))。

数据库 第二章 关系数据库习题

数据库 第二章 关系数据库习题

第二章关系数据库一、单项选择题1.在下列选项中,_A__不是基本关系的性质。

A.不同列应有不同的数据类型B.不同列应有不同的列名C.行的顺序可以任意D.列的顺序可以任意2.在关系模型中,一个关系只能有一个 D 。

A.候选码B.外码C.内码D.主码3.在关系模型中,一个候选码 C 。

A.只能由两个以上的属性组成B.至多包含一个属性C.可以由一个或多个属性组成D.必须包含关系的全部属性4.设X是关系R的属性组,但不是R的主码,若X引用了关系S的主码Y,则称 C 。

A.X是S的外码B.Y是R的外码C.X是R的外码D.Y是S的外码5.设域D1、D2、D3分别有K1、K2、K3个元素,则D1⨯D2⨯D3的元组数为__A____。

A.K1⨯ K2⨯ K3B.K1+ K2+ K3C.(K1+ K2)⨯K3D.(K1+ K2)÷K3 6.关系数据库管理系统应能实现的专门关系运算包括 B 。

A.排序、索引、统计B.选择、投影、连接C.关联、更新、排序D.显示、打印、制表7.关系模式和关系数据库模式之间的关系是 D 。

A.关系模式是型,关系数据库模式是它的值B.关系数据库模式是型,关系模式是它的值C.关系模式是关系数据库模式的集合D.关系数据库模式是关系模式的集合8.关系和关系模式之间的关系是A。

A.关系模式是型,关系是它的值B.关系是型,关系模式是它的值C.关系模式是关系的集合D.关系是关系模式的集合9.关系数据库和关系数据库模式之间的关系是 B 。

A.关系数据库是型,关系数据库模式是它的值B.关系数据库模式是型,关系数据库是它的值C.关系数据库模式是关系数据库的集合D.关系数据库是关系数据库模式的集合10.关系和关系数据库之间的关系是 C 。

A.关系数据库是型,关系是它的值B.关系是型,关系数据库是它的值C.关系数据库是关系的集合D.关系是关系数据库的集合11.属性取空值的含义是 D 。

A .属性值为0B .属性值为空集合C .属性值为空格D .属性的值不知道12. C 称为关系模式。

《Oracle数据库应用》-练习题2

《Oracle数据库应用》-练习题2

《Oracle数据库应用》一、选择题(20分)1. 有一产品表(编号,名称,价格,数量,所属分类),下列语法不正确的是()A、select * from 产品表 where价格>1000B、select sum(价格) from 产品表 group by 所属分类 having max(价格)>1000C、select所属分类,sum(价格) from 产品表 where 价格>1000 group by 所属分类D、select所属分类,sum(价格) from 产品表 where max(价格)>1000 groupby 所属分类2.在建表时如果希望某列的值,在一定的范围内,应建什么样的约束?()A、primary keyB、uniqueC、checkD、not null3.你要在Oracle中定义SQL查询。

下列哪个数据库对象不能直接从select语句中引用?()A、表B、序列C、索引D、视图4. SQL *Plus中发出的下列语句:select ceil(256.342), floor(256.342), round(256.342), trunc(256.342) from dual; 下列哪个函数不返回结果256?()A、ceil()B、floor()C、round()D、trunc()5.在Oracle数据库的逻辑结构中有以下组件:A 表空间 B 数据块 C 区 D 段,这些组件从大到小依次是()。

A、表空间→数据块→区→段B、表空间→段→区→数据块C、表空间→区→数据块→段D、段→表空间→区→数据块6. 有数据”test”分别存放到char(10)和varchar2(10)类型的字段中,其实际存储长度为()A、 10 10B、 4 4C、 10 4D、 4 107.SQL语句中修改表结构的命令是()。

A、MODIFY TABLEB、MODIFY STRUCTUREC、ALTER TABLED、ALTER STRUCTURE8. DELETE FROM S WHERE 年龄>60语句的功能是______。

数据库第二章关系代数习题

数据库第二章关系代数习题

1.设有如图所示的关系S、SC和C,试用关系代数表达式表示下列查询语句:S C SCS# SNAME AGE SEX1 李强23 男2 刘丽22 女5 张友22 男C# CNAME TEACHERk1 C语言王华k5 数据库原理程军k8 编译原理程军S# C# GRADE1 k1 832 k1 855 k1 922 k5 905 k5 845 k8 80(1)检索”程军”老师所授课的课程号(C#)和课程名(CNAME)。

∏C#,CNAME(δTEACHER=程军(C))(2)检索年龄大于21的男学生学号(S#)和姓名(SNAME)。

∏S#,SNAME(δAGE>21∧SEX=男(S))(3)检索至少选修”程军”老师所授全部课程的学生姓名(SNAME)。

∏SNAME((∏S#,C#(SC)÷∏C#(δTEACHER=程军(C)))S)(4)检索”李强”同学不学课程的课程号(C#)。

∏C#(C)-∏C#(δSNAME=李强(S)SC)(5)检索至少选修两门课程的学号(S#)。

∏S#(δ1=4∧2≠5(SC×SC))(6)检索全部学生都选修的课程的课程号(C#)和课程名(CNAME)。

∏C#,CNAME(∏S#,C#(SC)÷∏S#(S)C)(7)检索选修课程包含”程军”老师所授课程之一的学生学号(S#)。

∏C#(δTEACHER=程军(C)SC)(8)检索选修课程号为k1和k5的学生学号(S#)。

∏S#,C#(SC)÷∏C#(δC#=k1∨C#=k5(C))(9)检索选修全部课程的学生姓名(SNAME)。

∏SNAME((∏S#,C#(SC)÷∏C#(C))S)(10)检索选修课程包含学号为2的学生所选修课程的学生学号(S#)。

∏S#,C#(SC)÷∏C#(δS#=2(SC))(11)检索选修课程名为”C语言”的学生学号(S#)和姓名(SNAME)。

数据库习题带答案

数据库习题带答案

第一章绪论Ⅰ、学习要点1、准确掌握数据、数据库、数据库系统、数据库管理系统等基本术语、概念;2、数据独立性的概念、分类及实现途径;3、数据模型的概念、分类、要素及作用;4、数据库三级模式体系结构的含义及作用;5、关系数据模型的三要素内容。

Ⅱ、习题一、选择题:1、使用二维表格结构表达数据和数据间联系的数据模型是()A、层次模型B、网状模型C、关系模型D、实体—联系模型2、DB、DBS、DBMS间的关系是()A、DB包括DBMS和DBSB、DBMS包括DB和DBSC、DBS包括DB和DBMSD、DBS与DB和DBMS无关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、模式C、内模式D、数据模式10、数据库系统中用于定义和描述数据库逻辑结构的语言是()A、DMLB、DDLC、DCLD、SQL11、数据库系统支持的数据共享指的是()A、同一应用的多个程序共享同一数据集合B、多个用户、同一语言程序共享同一数据集合C、多个用户共享同一数据文件D、多种语言、多个用户、多个应用相互覆盖地使用同一数据集合12、数据库系统中,当内模式发生变化时,采用()来保证数据的物理独立性。

数据库技术复习题_二_填空题附答案

数据库技术复习题_二_填空题附答案

数据库技术复习题_二_填空题附答案数据库技术试题二、填空题1.一个类可以从直接的或间接的祖先中继承所有属性和方法。

采用这个方法提高了软件的共享性。

2.用树型结构表示实体类型及实体间联系的数据模型称为层次模型。

3.关系数据库的关系演算语言是以集合操作为基础的DML语言。

4.在函数信赖中,平凡的函数信赖根据 Armstrong 推理规则中的自反律就可推出。

5.分布式数据库中定义数据分片时,必须满足三个条件:完备性条件、重构条件和不相交条件。

6.DB 并发操作通常会带来三类问题,它们是丢失更新、不一致分析和读脏数据。

7.事务必须具有的四个性质是:原子性、一致性、隔离性和持久性。

8.分布式数据库系统中透明性层次越高,应用程序的编写越简单。

9.在有泛化/细化联系的对象类型之间,较低层的对象类型称为子类型。

10. 目前数据库领域中最常用的数据模型有层次模型,、网状模型,、关系模型、面向对象模型。

11. 数据管理技术经历了程序管理阶段、文件管理阶段、数据库系统管理阶段三个阶段。

12.SQL 语言集数据查询、数据操纵、、数据定义和数据控制功能于一体。

13.数据库系统采用的三级模式结构为外模式、、模式、内模式。

14.两个实体型之间的联系类型有一对一联系(1:1 )、一对多联系(1:n )、多对多( m:n)三类。

15.数据库中专门的关系运算包括选择、投影、连接、除法。

16. 满足第一范式(1NF) 的关系模式要求不包含重复组的关系。

17.如何构造出一个合适的数据逻辑结构是逻辑结构设计主要解决的问题。

18.当数据库被破坏后,如果事先保存了日志文件和数据库的副本,就有可能恢复数据库。

19.并发控制操作的主要方法是采用封锁机制,其类型有②排它锁(或 X 锁)③共享锁(或S锁)。

20.在关系模式 R(S,SN,D)和 K(D,CN,NM)中, R的主码是S,K的主码是 D,则 D在 R中称为外键。

21.对于函数依赖X→Y,如果 Y 是 X 的子集,则称X→Y为非平凡函数依赖。

数据库原理及应用习题课2

数据库原理及应用习题课2

关系模式R属性集为{A,B,C},函数依赖集F={AB→C,AC→B, B→C},则R属于( ). A.1NF B.2NF C.3NF D.BCNF 给定关系R(A1,A2,A3,A4)上的函数依赖集F={A1A3->A2,A2>A3},R候选关键字为( ).分解ρ={(A1,A2),(A1,A3)} ( ). A.A1A3 B.A1A2A3 C.A1A3A4 D.A2和A1A3 A.是无损联接的 B.是保持函数依赖的 C.既是无损联接又保持函数依赖 D.既是有损联接又不保持函数依赖 若R∈1NF,且R中只有一个主属性,则R必然满足( ) A.2NF B.3NF C.4NF D.BCNF 设有关系模式R(A,B,C,D),F是R上成立的FD集,F={B→C, C→D},则属性C的闭包C+为( ) A.BC B.BCD C.BD D.CD
设关系模式R(A,B,C,D),F={A→B,B→C},则 B+=________. 设有关系模式R(X,Y,Z),F={X→Y,Y→Z},则R 的 候选键是_____. 在关系模式的分解中,数据等价用 衡量,依赖等价用 衡量. 来衡量. 关系模式的好坏用 设有关系模式R(A,B,C,D),F是R上成立的FD集, F={AB →C,D → B},则F在模式ACD上的投影为 , F在模式AC上的投影为 .
有关系:教学(学号,教工号,课程号) 假定每个学生可以选修多门课程,每门课程可以由多名学生来选修,每个老师可 以讲授多门课程,每门课程只能由一个老师来讲授,那么该关系的主键是( ) A.(课程号,教工号) B.(学号,课程号) C.(学号,教工号) D.(学号,教工号,课程号) 消除多值依赖所引起的冗余是属于( ) A.1NF B.2NF C.3NF D.BCNF 下列叙述中正确的是( ) A.X →→Y,其中Z=U-X-Y=Φ,则称X→→Y为非平凡的多值依赖; B.X →→Y,其中Z=U-X-Y=Φ,则称X→→Y为平凡的多值依赖; C.对于函数依赖A1,A2,…,An→B来说,如果B是A中的某一个,则称为非 平凡函数依赖; D.对于函数依赖A1,A2,…,An→B来说,如果B是A中的某一个,则称为平 凡函数依赖;

数据库第二章练习题答案

数据库第二章练习题答案

数据库第二章练习题答案数据库第二章练习题答案数据库是现代信息系统中的重要组成部分,它负责存储、管理和处理数据。

在学习数据库的过程中,练习题是检验我们对知识掌握程度的重要方式。

本文将为大家提供数据库第二章练习题的详细答案,希望能对大家的学习有所帮助。

1. 什么是实体完整性?实体完整性是指数据库中的实体必须具有唯一的标识符,也就是主键。

每个实体都必须有一个主键,用来唯一标识该实体。

实体完整性保证了数据库中的实体的唯一性。

2. 什么是参照完整性?参照完整性是指数据库中的外键必须引用已经存在的主键。

外键是一个表中的字段,它引用了另一个表中的主键。

参照完整性保证了数据库中的关系的一致性。

3. 什么是主键?主键是用来唯一标识一个实体的字段或字段组合。

主键的值在表中必须是唯一的,且不能为空。

主键可以是一个字段,也可以是多个字段的组合。

4. 什么是外键?外键是一个表中的字段,它引用了另一个表中的主键。

外键用来建立两个表之间的关系,保证数据的一致性和完整性。

5. 什么是联合主键?联合主键是由多个字段组成的主键。

联合主键的值在表中必须是唯一的,且不能为空。

联合主键用来唯一标识一个实体。

6. 什么是关系型数据库?关系型数据库是以关系模型为基础的数据库。

关系模型是由表、行和列组成的,每个表代表一个实体,每一行代表一个实例,每一列代表一个属性。

关系型数据库使用SQL语言进行数据操作。

7. 什么是非关系型数据库?非关系型数据库是指不使用关系模型的数据库。

非关系型数据库使用不同的数据模型,如键值对、文档型、列族型等。

非关系型数据库具有高性能、高可扩展性和灵活性的特点。

8. 什么是数据库事务?数据库事务是由一组数据库操作组成的逻辑单位。

事务具有原子性、一致性、隔离性和持久性的特点。

原子性表示事务中的操作要么全部执行成功,要么全部执行失败;一致性表示事务执行前后数据库的状态保持一致;隔离性表示事务之间是相互隔离的;持久性表示事务提交后,其结果将永久保存在数据库中。

数据库系统概论练习题2

数据库系统概论练习题2

数据库系统概论一、单项选择题1. 关系数据模型上的关系运算分为( )A.关系代数和集合运算B.关系代数和关系演算C.关系演算和谓词演算D.关系代数和谓词演算2.在数据库系统中,保证数据及语义正确和有效的功能是( )A.并发控制B.存取控制C.安全控制D.完整性控制3.已知两个关系如下:假设R 的主键是A ,S 的主键是D ,在关系S 的定义中包含外键子句:“FOREIGN KEY (A ) REFERENCES R(A) ON DELETE RESTRICT ”,下列SQL 语句不能成功执行的是( )A .DELETE FROM R WHEREA =2B .DELETE FROM R WHERE A =3C .DELETE FROM S WHERE A =1D .DELETE FROM S WHERE A =24.一辆汽车由多个零部件组成,且相同的零部件可适用于不同型号的汽车,则汽车实体集与零部件实体集之间的联系是( )A. 1:1B. 1:MC. M:1D. M:N5.系统故障会造成( )A.内存数据丢失B.硬盘数据丢失C.软盘数据丢失D.磁带数据丢失6.SQL 的SELECT 语句中,“HAVING 条件表达式”用来筛选满足条件的( )A .列B .行C .关系D .分组7.设关系模式R (A ,B ,C ),F 是R 上成立的FD 集,F ={A →B ,C →B },R 上的分解ρ={AB ,AC },则分解ρ( )A .保持函数依赖集FB .丢失了C →BC .丢失了A →BD .是否保持FD ,由R 的当前关系确定8.任何一个满足2NF 但不满足3NF 的关系模式都不存在( )A.主属性对候选键的部分依赖B.非主属性对候选键的部分依赖C.主属性对候选键的传递依赖D.非主属性对候选键的传递依赖9.如果事务T 已在数据R 上加了X 锁,则其他事务在数据R 上( )A .只可加X 锁B .只可加S 锁C .可加S 锁或X 锁D .不能加任何锁10.用下面的SQL 语句建立一个基本表:CREATE TABLE Student(Sno CHAR (4) NOT NULL,Sname CHAR (8) NOT NULL,Sex CHAR (2),Age SMALLINT)可以插入到表中的元组是( )A.′5021′,′刘祥′,男,21B.NULL ,′刘祥′,NULL ,21C.′5021′,NULL ,男,21D.′5021′,′刘祥′,NULL ,NULL11.若想把对关系S修改权限赋予用户lin,并允许用户lin把对关系S的修改权限赋予其他人,则应执行的SQL语句是()A.GRANT UPDATE ON S TO lin WITH GRANT OPTIONB.GRANT UPDATE ON S TO linC.REVOKE UPDATE ON S FROM lin RESTRICTD.REVOKE UPDATE ON S FROM lin RESTRICT chen二、填空题12.参照完整性规则是对键的约束。

数据库复习题 (2)

数据库复习题 (2)

三、应用题设有如下实体:学生:学号、单位、姓名、性别、年龄、选修课程名课程:编号、课程名、开课单位、任课教师号教师:教师号、姓名、性别、职称、讲授课程编号单位:单位名称、电话、教师号、教师名上述实体中存在如下联系:(1).一个学生可选修多门课程,一门课程可为多个学生选修;(2).一个教师可讲授多门课程,一门课程可为多个教师讲授;(3).一个单位可有多个教师,一个教师只能属于一个单位。

试完成如下工作:(1).分别设计学生选课和教师任课两个局部信息的结构E-R图。

(2).将上述设计完成的E-R图合并成一个全局E-R图。

(3).将该全局E-R图转换为等价的关系模型表示的数据库逻辑结构。

解:(1).学生选课、教师任课局部E-R图如下所示。

教师授课局部E-R图(2).合并后的全局E-R图如下所示。

全局E-R图为避免图形复杂,下面给出各实体属性:单位:单位名、电话学生:学号、姓名、性别、年龄教师:教师号、姓名、性别、职称课程:编号、课程号(3).该全局E-R图转换为等价的关系模型表示的数据库逻辑结构如下:单位(单位名,电话)教师(教师号,姓名,性别,职称,单位名)课程(课程编号,课程名,单位名)学生(学号,姓名,性别,年龄,单位名)讲授(教师号,课程编号)选修(学号,课程编号)2、工厂(包括厂名,厂长名)需建立一管理数据库存贮以下信息:一个厂内有多个车间,每个车间有车间号、主任姓名、地址、电话;一个车间有多个工人,每个工人有职工号、姓名、年龄、性别、工种;一个车间生产多种产品,产品有产品号、价格;一个车间生产多种零件,一种零件也可能为多个车间制造,零件有零件号、重量、价格;一种产品由多种零件组成,一种零件也可装配到多种产品中;产品与零件均存入仓库中;厂内有多个仓库,仓库有仓库号、主任姓名、电话。

试(1)画出该系统的实体-联系模型E-R图。

(2)给出相应的关系数据模型。

(1)检索“程军”老师所授课程的课程号(C#)和课程名(CNAME)。

《数据库原理》1-2章作业习题

《数据库原理》1-2章作业习题

《数据库原理》知识点第一章1.什么是4D(Data, DB、DBMS、DBS),它们之间的关系?数据:data,保存在DBS中的信息。

数据库:database DB数据库系统:database system DBSDB(英文全称data base,数据库)是依照某种数据模型组织起来并存放二级存储器中的数据集合。

这种数据集合具有如下特点:尽可能不重复,以最优方式为某个特定组织的多种应用服务,其数据结构独立于使用它的应用程序,对数据的增、删、改和检索由统一软件进行管理和控制。

从发展的历史看,数据库是数据管理的高级阶段,它是由文件管理系统发展起来的。

数据库管理系统(database management system)是一种操纵和管理数据库的大型软件,是用于建立、使用和维护数据库,简称dbms。

它对数据库进行统一的管理和控制,以保证数据库的安全性和完整性。

用户通过dbms访问数据库中的数据,数据库管理员也通过dbms进行数据库的维护工作。

它提供多种功能,可使多个应用程序和用户用不同的方法在同时或不同时刻去建立,修改和询问数据库。

它使用户能方便地定义和操纵数据,维护数据的安全性和完整性,以及进行多用户下的并发控制和恢复数据库。

2.数据模型的组成要素有哪些?数据模型指按照特定的形式把数据组织起来。

组成要素包括数据本身,以及数据之间的关系。

数据模型通常有关系型,网状型,层次型,其中关系型目前最为常用。

3.ER模型的组成要素有哪些?实体型、属性和联系所组成4.学校中有若干系,每个系有若干班级和教研室,每个教研室有若干教师,其中有的教授和副教授每人各带若干研究生,每个班有若干学生,每个学生选修若干课程,每门课程可由若干学生选修。

请用E-R图画出此学校的概念模型。

5.某工厂生产若干产品,每种产品由不同的零件组成,有的零件可用在不同的产品上。

这些零件由不同的原材料制成,不同零件所用的材料可以相同。

这些零件按照所属的不同产品分别放在仓库中,原材料按照类别放在若干仓库中。

大学数据库-第2章习题解答

大学数据库-第2章习题解答

第2章习题解答〖2.1〗定义并解释术语:实体实体型实体集属性码实体联系图(E-R图)数据模型答:①实体:现实世界中存在的可以相互区分的事物或概念称为实体。

②实体型:现实世界中,对具有相同性质、服从相同规则的一类事物(或概念,即实体)的抽象称为实体型。

③实体集:具有相同特征或能用同样特征描述的实体的集合称为实体集。

④属性:属性为实体的某一方面特征的抽象表示。

⑤码:也称为关键字,能够唯一标识一个实体。

⑥实体联系图(E-R图):实体联系方法(E-R图法)是用来描述现实世界中概念模型的一种著名方法,提供了表示实体集、属性和联系的方法。

⑦数据模型:一组严格定义的概念集合。

这些概念精确地描述了系统的数据结构、数据操作和数据完整性约束条件。

〖2.2〗试述数据模型的概念、数据模型的作用和数据模型的三个要素。

答:①数据模型是一组严格定义的概念集合,这些概念精确地描述了系统的数据结构、数据操作和数据完整性约束条件。

数据模型是通过概念模型数据化处理得到的。

②数据库是根据数据模型建立的,因而数据模型是数据库系统的基础。

③数据模型的三要素是数据结构、数据操作和完整性约束条件。

数据结构是所研究的对象类型的集合;数据操作是指对数据库中各种数据对象允许执行的操作集合;数据约束条件是一组数据完整性规则的集合。

〖2.3〗试述信息模型的作用。

答:信息模型是对信息世界的管理对象、属性及联系等信息的描述形式。

信息模型不依赖于计算机及DBMS,它是现实世界的真实而全面的反映。

信息模型数据化处理后可得到数据模型。

〖2.4〗试给出三个实际部门的E-R图,要求实体型之间具有一对一、一对多、多对多各种不同的联系。

答:见图。

题2.4 E-R图图中:部门和负责人间的联系是一对一的联系;一个学生可以借阅多本书,一本书只能一个人借,学生和借阅间的联系为一对多的联系;一个学生可以参加多个社会团体,一个社会团体有多个学生参加,学生和社会团体间的联系为多对多的联系。

  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

1.设要建立一个港口员工信息数据库,该港口有多个下属部门,每一部门有多个职员,一个职员仅隶属于一个部门,且一个职员仅在一个岗位上工作,但一个岗位有很多职员参加。

部门的属性有:部门编号、部门名称、地址。

职员的属性有:职员号、姓名、性别、年龄、学历。

岗位的属性有:岗位编号、岗位名称、所属部门编号、在岗职员号
(1)画出由这三个表组成的基本E-R图。

(5分)
(2)写出岗位表的数据字典。

(3分)
(3)用关系代数表达式表示求所属岗位名称为‘装卸工’的所有职工的职员号、姓名、性别、年龄和学历。

(5分)
2.三个表即泊位基本信息表、船舶基本信息表和到港信息表,它们的结构如下: B(B#, BNUM,LEN), S(S#, SN,CON,COM,GO)
DG(B#, S#, TIME,STATE,GONUM)
其中:B#为泊位编号,BNUM为泊位个数,LEN为泊位长度。

S#为船编号,SN 为船名,CON为所属国家,COM为所属公司,GO为货物类别。

TIME为船舶到港时间,STATE为装卸货状态,GONUM为目前的装卸数量。

(1)检索所有泊位长度大于100的泊位编号和泊位个数。

(3分)
共5分,实体1个1分,关系写错或缺少1个1分。

(2)岗位信息表={岗位编号+岗位名称+所属部门编号+{在岗职工号}} 共3分,少一个括号扣1分
(3)πσ
职工号,姓名,性别,年岗位名称='装卸工’
((职工岗位))连接、投影和选择少一个运算扣1分。

相关文档
最新文档