数据库系统实现课后习题答案

合集下载

(完整版)数据库课后习题及答案

(完整版)数据库课后习题及答案

第一章数据库系统概述选择题1实体-联系模型中,属性是指(C)A.客观存在的事物B.事物的具体描述C.事物的某一特征D.某一具体事件2对于现实世界中事物的特征,在E-R模型中使用(A)A属性描述B关键字描述C二维表格描述D实体描述3假设一个书店用这样一组属性描述图书(书号,书名,作者,出版社,出版日期),可以作为“键”的属性是(A)A书号B书名C作者D出版社4一名作家与他所出版过的书籍之间的联系类型是(B)A一对一B一对多C多对多D都不是5若无法确定哪个属性为某实体的键,则(A)A该实体没有键B必须增加一个属性作为该实体的键C取一个外关键字作为实体的键D该实体的所有属性构成键填空题1对于现实世界中事物的特征在E-R模型中使用属性进行描述2确定属性的两条基本原则是不可分和无关联3在描述实体集的所有属性中,可以唯一的标识每个实体的属性称为键4实体集之间联系的三种类型分别是1:1 、1:n 、和m:n5数据的完整性是指数据的正确性、有效性、相容性、和一致性简答题一、简述数据库的设计步骤答:1需求分析:对需要使用数据库系统来进行管理的现实世界中对象的业务流程、业务规则和所涉及的数据进行调查、分析和研究,充分理解现实世界中的实际问题和需求。

分析的策略:自下而上——静态需求、自上而下——动态需求2数据库概念设计:数据库概念设计是在需求分析的基础上,建立概念数据模型,用概念模型描述实际问题所涉及的数据及数据之间的联系。

3数据库逻辑设计:数据库逻辑设计是根据概念数据模型建立逻辑数据模型,逻辑数据模型是一种面向数据库系统的数据模型。

4数据库实现:依据关系模型,在数据库管理系统环境中建立数据库。

二、数据库的功能答:1提供数据定义语言,允许使用者建立新的数据库并建立数据的逻辑结构2提供数据查询语言3提供数据操纵语言4支持大量数据存储5控制并发访问三、数据库的特点答:1数据结构化。

2数据高度共享、低冗余度、易扩充3数据独立4数据由数据库管理系统统一管理和控制:(1)数据安全性(2)数据完整性(3)并发控制(4)数据库恢复第二章关系模型和关系数据库选择题1把E-R模型转换为关系模型时,A实体(“一”方)和B实体(“多”方)之间一对多联系在关系模型中是通过(A)来实现的A将A关系的关键字放入B关系中B建立新的关键字C建立新的联系D建立新的实体2关系S和关系R集合运算的结果中既包含S中元组也包含R中元组,但不包含重复元组,这种集合运算称为(A)A并运算B交运算C差运算D积运算3设有关系R1和R2,经过关系运算得到结果S,则S是一个(D)A字段B记录C数据库D关系4关系数据操作的基础是关系代数。

数据库系统基础教程(第二版)课后习题答案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。

《数据库系统概论》课后习题及参考答案

《数据库系统概论》课后习题及参考答案

课后作业习题《数据库系统概论》课程部分习题及参考答案第一章绪论(教材41页)1.试述数据、数据库、数据库系统、数据库管理系统得概念。

数据:描述事物得符号记录称为数据。

数据得种类有文字、图形、图象、声音、正文等等。

数据与其语义就是不可分得。

数据库:数据库就是长期储存在计算机内、有组织得、可共享得数据集合。

数据库中得数据按一定得数据模型组织、描述与储存,具有较小得冗余度、较高得数据独立性与易扩展性,并可为各种用户共享。

数据库系统:数据库系统( DBS)就是指在计算机系统中引入数据库后得系统构成.数据库系统由数据库、数据库管理系统(及其开发工具)、应用系统、数据库管理员构成。

数据库管理系统:数据库管理系统 (DBMS)就是位于用户与操作系统之间得一层数据管理软件.用于科学地组织与存储数据、高效地获取与维护数据.DBMS主要功能包括数据定义功能、数据操纵功能、数据库得运行管理功能、数据库得建立与维护功能.2.使用数据库系统有什么好处?使用数据库系统得好处就是由数据库管理系统得特点或优点决定得.使用数据库系统得好处很多,例如可以大大提高应用开发得效率,方便用户得使用,减轻数据库系统管理人员维护得负担等。

为什么有这些好处,可以结合第 5题来回答。

使用数据库系统可以大大提高应用开发得效率。

因为在数据库系统中应用程序不必考虑数据得定义、存储与数据存取得具体路径,这些工作都由DBMS来完成。

此外,当应用逻辑改变,数据得逻辑结构需要改变时,由于数据库系统提供了数据与程序之间得独立性。

数据逻辑结构得改变就是DBA得责任,开发人员不必修改应用程序,或者只需要修改很少得应用程序。

从而既简化了应用程序得编制,又大大减少了应用程序得维护与修改。

使用数据库系统可以减轻数据库系统管理人员维护系统得负担.因为 DBMS在数据库建立、运用与维护时对数据库进行统一得管理与控制,包括数据得完整性、安全性,多用户并发控制,故障恢复等等都由DBMS执行。

数据库课后习题作业答案

数据库课后习题作业答案

数据库课后习题作业答案《数据库系统概论》课程习题及参考答案第⼀章绪论(教材37页)1.试述数据、数据库、数据库系统、数据库管理系统的概念。

答:数据:描述事物的符号记录称为数据。

数据的种类有⽂字、图形、图像、声⾳、正⽂等等。

数据与其语义是不可分的。

数据库:数据库是长期储存在计算机内、有组织的、可共享的数据集合。

数据库中的数据按⼀定的数据模型组织、描述和储存,具有较⼩的冗余度、较⾼的数据独⽴性和易扩展性,并可为各种⽤户共享。

数据库系统:数据库系统(DBS)是指在计算机系统中引⼊数据库后的系统构成。

数据库系统由数据库、数据库管理系统(及其开发⼯具)、应⽤系统、数据库管理员构成。

数据库管理系统:数据库管理系统(DBMS)是位于⽤户与操作系统之间的⼀层数据管理软件。

⽤于科学地组织和存储数据、⾼效地获取和维护数据。

DBMS 主要功能包括数据定义功能、数据操纵功能、数据库的运⾏管理功能、数据库的建⽴和维护功能。

2.使⽤数据库系统有什么好处?答:使⽤数据库系统的好处是由数据库管理系统的特点或优点决定的。

使⽤数据库系统的好处很多,例如可以⼤⼤提⾼应⽤开发的效率,⽅便⽤户的使⽤,减轻数据库系统管理⼈员维护的负担等。

为什么有这些好处,可以结合第 5题来回答。

使⽤数据库系统可以⼤⼤提⾼应⽤开发的效率。

因为在数据库系统中应⽤程序不必考虑数据的定义、存储和数据存取的具体路径,这些⼯作都由 DBMS来完成。

此外,当应⽤逻辑改变,数据的逻辑结构需要改变时,由于数据库系统提供了数据与程序之间的独⽴性。

数据逻辑结构的改变是 DBA的责任,开发⼈员不必修改应⽤程序,或者只需要修改很少的应⽤程序。

从⽽既简化了应⽤程序的编制,⼜⼤⼤减少了应⽤程序的维护和修改。

使⽤数据库系统可以减轻数据库系统管理⼈员维护系统的负担。

因为 DBMS 在数据库建⽴、运⽤和维护时对数据库进⾏统⼀的管理和控制,包括数据的完整性、安全性,多⽤户并发控制,故障恢复等等都由DBMS执⾏。

数据库系统教程课后习题答案(部分)--何玉洁 李宝安

数据库系统教程课后习题答案(部分)--何玉洁 李宝安

第一部分基础理论第1章数据库概述1.试说明数据、数据库、数据库管理系统和数据库系统的概念。

数据:描述事务的符号记录数据库:存储数据的仓库数据库管理系统:用于管理和维护数据的系统软件数据库系统:计算机中引入数据库后的系统,包括数据库,数据库管理系统,应用程序,数据库管理员2.数据管理技术的发展主要经历了哪几个阶段?两个阶段,文件管理和数据库管理9.数据独立性指的是什么?应用程序不因数据的物理表示方式和访问技术改变而改变,分为逻辑独立性和物理独立性。

物理独立性是指当数据的存储结构或存储位置发生变化时,不影响应用程序的特性;逻辑独立性是指当表达现实世界的信息内容发生变化时,不影响应用程序的特性。

10.数据库系统由哪几部分组成?由数据库、数据库管理系统、应用程序、数据库管理员组成。

第2章数据模型与数据库系统的结构4.说明实体一联系模型中的实体、属性和联系的概念。

实体是具有公共性质的并可相互区分的现实世界对象的集合。

属性是实体所具有的特征或性质。

联系是实体之间的关联关系。

6.数据库系统包含哪三级模式?试分别说明每一级模式的作用。

外模式、模式和内模式。

外模式:是对现实系统中用户感兴趣的整体数据结构的局部描述,用于满足不同用户对数据的需求,保证数据安全。

模式:是数据库中全体数据的逻辑结构和特征的描述,它满足所有用户对数据的需求。

内模式:是对整个数据库的底层表示,它描述了数据的存储结构。

7.数据库管理系统提供的两级映像的作用是什么?它带来了哪些功能?两级映像是外模式/模式映像和模式/内模式映像。

外模式/模式映像保证了当模式发生变化时可以保证外模式不变,从而使用户的应用程序不需要修改,保证了程序与数据的逻辑独立性。

模式/内模式映像保证了当内模式发生变化,比如存储位置或存储文件名改变,可以保持模式不变,保证了程序与数据的物理独立性。

两级印象保证了应用程序的稳定性。

第3章关系数据库1.试述关系模型的三个组成部分。

数据结构、关系操作集合、关系完整性约束2.解释下列术语的含义:(3)候选码当一个属性或属性集的值能够唯一标识一个关系的元组,而又不包含多余的元素,则称该属性或属性集为候选码。

数据库系统原理课后习题参考答案

数据库系统原理课后习题参考答案

数据库系统原理课后习题参考答案(总8页)--本页仅作为文档封面,使用时请直接删除即可----内页可以根据需求调整合适字体及大小--第一章数据库系统概述选择题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.请简述关系规范化过程。

数据库系统原理(2018年版)课后习题参考答案解析

数据库系统原理(2018年版)课后习题参考答案解析
第三代数据库系统必须支持数据管理、对象管理和知识管理
第三代数据库系统必须保持或集成第二代数据库系统技术
第三代数据库系统必须对其他系统开放
2.描述数据仓库粒度的概念P182
粒度是指数据仓库数据单位中保存数据的细化或综合程度
3.描述数据挖掘技术的能P183
概念描述
关联分析
分类与预测
聚类
孤立点检测
趋势和演变分析
视图的内容是由存储在数据库中进行查询操作的SQL语句定义的,它的列数据与行数据均来自于定义视图的查询所引用的基本表。
视图不适宜数据集的形式存储在数据库中的,它所对应的数据实际上是存储在视图所引用的基本表中的。
视图是用来查看存储在别处的数据的一种虚拟表,本身不存储数据。
第五章 数据库编程
简答题
1.请简述存储过程的概念P125
答:参照完整性约束是指:若属性或属性组F是基本关系R的外码,与基本关系S的主码K相对应,则对于R中每个元组在F上的取值只允许有两种可能,要么是空值,要么与S中某个元组的主码值对应。
3.请简述关系规范化过程。
答:对于存在数据冗余、插入异常、删除异常问题的关系模式,应采取将一个关系模式分解为多个关系模式的方法进行处理。一个低一级范式的关系模式,通过模式分解可以转换为若干个高一级范式的关系模式,这就是所谓的规范化过程。
数据库系统是指在计算机中引入数据库技术之后的系统,包括数据库、数据库管理系统及相关实用工具、应用程序、数据库管理员和用户。
2.请简述早数据库管理技术中,与人工管理、文件系统相比,数据库系统的优点。
数据共享性高
数据冗余小
易于保证数据一致性
数据独立性高
可以实施统一管理与控制
减少了应用程序开发与维护的工作量

数据库系统原理教程课后习题及答案(第九章)

数据库系统原理教程课后习题及答案(第九章)

第9章数据库恢复技术1.试述事务的概念及事务的4 个特性。

答:事务是用户定义的一个数据库操作序列,这些操作要么全做要么全不做,是一个不可分割的工作单位。

事务具有4 个特性:原子性(Atomicity )、一致性(consistency )、隔离性( Isolation )和持续性(Durability )。

这4 个特性也简称为ACID 特性。

原子性:事务是数据库的逻辑工作单位,事务中包括的诸操作要么都做,要么都不做。

一致性:事务执行的结果必须是使数据库从一个一致性状态变到另一个一致性状态。

隔离性:一个事务的执行不能被其他事务干扰。

即一个事务内部的操作及使用的数据对其他并发事务是隔离的,并发执行的各个事务之间不能互相干扰。

持续性:持续性也称永久性(Perfnanence ) ,指一个事务一旦提交,它对数据库中数据的改变就应该是永久性的。

接下来的其他操作或故障不应该对其执行结果有任何影响。

2 .为什么事务非正常结束时会影响数据库数据的正确性,请列举一例说明之。

答:事务执行的结果必须是使数据库从一个一致性状态变到另一个一致性状态。

如果数据库系统运行中发生故障,有些事务尚未完成就被迫中断,这些未完成事务对数据库所做的修改有一部分已写入物理数据库,这时数据库就处于一种不正确的状态,或者说是不一致的状态。

例如某工厂的库存管理系统中,要把数量为Q 的某种零件从仓库1 移到仓库2 存放。

则可以定义一个事务T , T 包括两个操作;Ql = Ql 一Q , Q2= Q2 + Q。

如果T 非正常终止时只做了第一个操作,则数据库就处于不一致性状态,库存量无缘无故少了Q 。

3 .数据库中为什么要有恢复子系统?它的功能是什么?答:因为计算机系统中硬件的故障、软件的错误、操作员的失误以及恶意的破坏是不可避免的,这些故障轻则造成运行事务非正常中断,影响数据库中数据的正确性,重则破坏数据库,使数据库中全部或部分数据丢失,因此必须要有恢复子系统。

数据库课后习题答案

数据库课后习题答案

第一章绪论1、试述数据、数据库、数据库管理系统、数据库系统的概念。

答:描述事物的符号记录称为数据;数据库是长期储存在计算机内的、有组织的、可共享的数据集合;数据库管理系统是位于用户与操作系统之间的一层数据管理软件; 数据库系统是指在计算机系统中引入数据库后的系统,一般由数据库、数据库管理系统(及其开发工具)、应用系统、数据库管理员和用户构成。

2.使用数据库系统有什么好处?答:数据库系统使信息系统从以加工数据的程序为中心转向围绕共享的数据库为中心的阶段,这样既便于数据的集中管理,又有利于应用程序的研制和维护,提高了数据的利用率和相容性,提高了决策的可靠性。

3.试述文件系统与数据库系统的区别和联系。

答:1)数据结构化是数据库与文件系统的根本区别。

在文件系统中,相互独立的文件的记录内部是有结构的,管其记录内部已有了某些结构,但记录之间没有联系。

数据库系统实现整体数据的结构化,是数据库的主要特征之一。

2)在文件系统中,数据的最小存取单位是记录,粒度不能细到数据项。

而在数据库系统中,存取数据的方式也很灵活,可以存取数据库中的某一个数据项、一组数据项一个记录或或一组记录。

3)文件系统中的文件是为某一特定应用服务的,文件的逻辑结构对该应用程序来说是优化的,因此要想对现有的数据再增加一些新的应用会很困难,系统不容易扩充。

而在数据库系统中数据不再针对某一应用,而是面向全组织,具有整体的结构化。

5.试述数据库系统的特点。

答:数据结构化;数据的共享性高、冗余度低、易扩充;数据独立性高;数据由DBMS统一管理和控制。

6.数据库管理系统的主要功能有哪些?答:数据定义功能、数据操纵功能、数据库的运行管理、数据库的建立和维护功能。

7.试述数据模型的概念(13页)、数据模型的作用、数据模型的三个要素。

答:数据模型(Data Model)也是一种模型,它是现实世界数据特征的抽象。

作用:在数据库中用数据模型来抽象、表示和处理现实世界中的数据和信息。

数据库课后习题(第一至四章)

数据库课后习题(第一至四章)

第一章1.1 名词解释(1) DB:即数据库(Database),是统一管理的相关数据的集合。

DB能为各种用户共享,具有最小冗余度,数据间联系密切,而又有较高的数据独立性。

(2) DBMS:即数据库管理系统(Database Management System),是位于用户与操作系统之间的一层数据管理软件,为用户或应用程序提供访问DB的方法,包括DB的建立、查询、更新及各种数据控制。

DBMS总是基于某种数据模型,可以分为层次型、网状型、关系型、面向对象型DBMS。

(3) DBS:即数据库系统(Database System),是实现有组织地、动态地存储大量关联数据,方便多用户访问的计算机软件、硬件和数据资源组成的系统,即采用了数据库技术的计算机系统。

(4) 1:1联系:如果实体集E1中的每个实体最多只能和实体集E2中的一个实体有联系,反之亦然,那么实体集E1对E2的联系称为“一对一联系”,记为“1:1”。

(5) 1:N联系:如果实体集E1中每个实体与实体集E2中任意个(零个或多个)实体有联系,而E2中每个实体至多和E1中的一个实体有联系,那么E1对E2的联系是“一对多联系”,记为“1:N”。

(6) M:N联系:如果实体集E1中每个实体与实体集E2中任意个(零个或多个)实体有联系,反之亦然,那么E1对E2的联系是“多对多联系”,记为“M:N”。

(7) 数据模型:模型是对现实世界的抽象。

在数据库技术中,表示实体类型及实体类型间联系的模型称为“数据模型”。

它可分为两种类型:概念数据模型和结构数据模型。

(8) 概念数据模型:是独门于计算机系统的模型,完全不涉及信息在系统中的表示,只是用来描述某个特定组织所关心的信息结构。

(9) 结构数据模型:是直接面向数据库的逻辑结构,是现实世界的第二层抽象。

这类模型涉及到计算机系统和数据库管理系统,所以称为“结构数据模型”。

结构数据模型应包含:数据结构、数据操作、数据完整性约束三部分。

数据库课后习题参考答案与解析

数据库课后习题参考答案与解析

第1章数据概述一.选择题1.下列关于数据库管理系统的说法,错误的是CA.数据库管理系统与操作系统有关,操作系统的类型决定了能够运行的数据库管理系统的类型B.数据库管理系统对数据库文件的访问必须经过操作系统实现才能实现C.数据库应用程序可以不经过数据库管理系统而直接读取数据库文件D.数据库管理系统对用户隐藏了数据库文件的存放位置和文件名2.下列关于用文件管理数据的说法,错误的是DA.用文件管理数据,难以提供应用程序对数据的独立性B.当存储数据的文件名发生变化时,必须修改访问数据文件的应用程序C.用文件存储数据的方式难以实现数据访问的安全控制D.将相关的数据存储在一个文件中,有利于用户对数据进行分类,因此也可以加快用户操作数据的效率3.下列说法中,不属于数据库管理系统特征的是CA.提供了应用程序和数据的独立性B.所有的数据作为一个整体考虑,因此是相互关联的数据的集合C.用户访问数据时,需要知道存储数据的文件的物理信息D.能够保证数据库数据的可靠性,即使在存储数据的硬盘出现故障时,也能防止数据丢失5.在数据库系统中,数据库管理系统和操作系统之间的关系是DA.相互调用B.数据库管理系统调用操作系统C.操作系统调用数据库管理系统D.并发运行6.数据库系统的物理独立性是指DA.不会因为数据的变化而影响应用程序B.不会因为数据存储结构的变化而影响应用程序C.不会因为数据存储策略的变化而影响数据的存储结构D.不会因为数据逻辑结构的变化而影响应用程序7.数据库管理系统是数据库系统的核心,它负责有效地组织、存储和管理数据,它位于用户和操作系统之间,属于AA.系统软件B.工具软件C.应用软件D.数据软件8.数据库系统是由若干部分组成的。

下列不属于数据库系统组成部分的是B A.数据库B.操作系统C.应用程序D.数据库管理系统9.下列关于客户/服务器结构和文件服务器结构的描述,错误的是DA.客户/服务器结构将数据库存储在服务器端,文件服务器结构将数据存储在客户端B.客户/服务器结构返回给客户端的是处理后的结果数据,文件服务器结构返回给客户端的是包含客户所需数据的文件C.客户/服务器结构比文件服务器结构的网络开销小D.客户/服务器结构可以提供数据共享功能,而用文件服务器结构存储的数据不能共享数据库是相互关联的数据的集合,它用综合的方法组织数据,具有较小的数据冗余,可供多个用户共享,具有较高的数据独立性,具有安全控制机制,能够保证数据的安全、可靠,允许并发地使用数据库,能有效、及时地处理数据,并能保证数据的一致性和完整性。

数据库第二版课后习题答案

数据库第二版课后习题答案

数据库第二版课后习题答案数据库第二版课后习题答案数据库是计算机科学中重要的概念之一,它提供了一种有效地存储和管理数据的方式。

数据库系统的设计与实现是数据库课程的重要内容之一。

在学习数据库课程时,课后习题是巩固知识和提高能力的重要途径。

本文将为大家提供数据库第二版课后习题的答案,希望对大家的学习有所帮助。

第一章数据库系统概述1. 数据库是什么?答:数据库是一个有组织的、可共享的、可维护的数据集合,它以一定的数据模型为基础,描述了现实世界中某个特定领域的数据和关系。

2. 数据库系统的特点有哪些?答:数据库系统具有以下特点:- 数据的独立性:数据库系统将数据与程序相分离,使得数据的修改不会影响到程序的运行。

- 数据的共享性:多个用户可以同时访问数据库,并且可以共享数据。

- 数据的冗余性小:通过数据库系统的数据一致性和完整性约束,可以减少数据的冗余性。

- 数据的易扩展性:数据库系统可以方便地进行扩展和修改,以满足不同需求。

- 数据的安全性:数据库系统提供了权限管理和数据加密等机制,保证数据的安全性。

第二章关系数据库与SQL1. 什么是关系数据库?答:关系数据库是一种基于关系模型的数据库,它使用表格(关系)来表示和存储数据。

关系数据库中的数据以行和列的形式组织,每个表格代表一个实体集,每一行代表一个实体,每一列代表一个属性。

2. 什么是SQL?答:SQL(Structured Query Language)是一种用于管理关系数据库的语言。

它包含了数据定义语言(DDL)、数据操纵语言(DML)和数据控制语言(DCL)等部分。

通过SQL,用户可以对数据库进行创建、查询、更新和删除等操作。

第三章数据库设计1. 数据库设计的步骤有哪些?答:数据库设计的步骤包括:- 需求分析:确定数据库的需求和目标,了解用户的需求。

- 概念设计:根据需求分析的结果,设计数据库的概念模型,包括实体、属性和关系等。

- 逻辑设计:将概念模型转换为逻辑模型,包括表格的设计、关系的建立和约束的定义等。

数据库实用教程课后习题参考答案(1-4章)

数据库实用教程课后习题参考答案(1-4章)

数据库实用教程课后习题参考答案(1-4章)第1、2章1.1 名词解释:◆ DB:数据库(Database),DB是统一管理的相关数据的集合。

DB能为各种用户共享,具有最小冗余度,数据间联系密切,而又有较高的数据独立性。

◆ DBMS:数据库管理系统(Database Management System),DBMS是位于用户与操作系统之间的一层数据管理软件,为用户或应用程序提供访问DB的方法,包括DB的建立、查询、更新及各种数据控制。

DBMS总是基于某种数据模型,可以分为层次型、网状型、关系型、面向对象型DBMS。

◆ DBS:数据库系统(Database System),DBS是实现有组织地、动态地存储大量关联数据,方便多用户访问的计算机软件、硬件和数据资源组成的系统,即采用了数据库技术的计算机系统。

◆ 1:1联系:如果实体集E1中的每个实体最多只能和实体集E2中的一个实体有联系,反之亦然,好么实体集E1对E2的联系称为“一对一联系”,记为“1:1”。

◆ 1:N联系:如果实体集E1中每个实体与实体集E2中任意个(零个或多个)实体有联系,而E2中每个实体至多和E1中的一个实体有联系,那么E1对E2的联系是“一对多联系”,记为“1:N”。

◆ M:N联系:如果实体集E1中每个实体与实体集E2中任意个(零个或多个)实体有联系,反之亦然,那么E1对E2的联系是“多对多联系”,记为“M:N”。

◆ 数据模型:表示实体类型及实体类型间联系的模型称为“数据模型”。

它可分为两种类型:概念数据模型和结构数据模型。

◆ 概念数据模型:它是独门于计算机系统的模型,完全不涉及信息在系统中的表示,只是用来描述某个特定组织所关心的信息结构。

◆ 结构数据模型:它是直接面向数据库的逻辑结构,是现实世界的第二层抽象。

这类模型涉及到计算机系统和数据库管理系统,所以称为“结构数据模型”。

结构数据模型应包含:数据结构、数据操作、数据完整性约束三部分。

数据库系统教程课后答案(施伯乐)(第三版)

数据库系统教程课后答案(施伯乐)(第三版)

第1章数据库概论1.1 基本内容分析1.1.1 本章的重要概念(1)DB、DBMS和DBS的定义(2)数据管理技术的发展阶段人工管理阶段、文件系统阶段、数据库系统阶段和高级数据库技术阶段等各阶段的特点。

(3)数据描述概念设计、逻辑设计和物理设计等各阶段中数据描述的术语,概念设计中实体间二元联系的描述(1:1,1:N,M:N)。

(4)数据模型数据模型的定义,两类数据模型,逻辑模型的形式定义,ER模型,层次模型、网状模型、关系模型和面向对象模型的数据结构以及联系的实现方式。

(5)DB的体系结构三级结构,两级映像,两级数据独立性,体系结构各个层次中记录的联系。

(6)DBMSDBMS的工作模式、主要功能和模块组成。

(7)DBSDBS的组成,DBA,DBS的全局结构,DBS结构的分类。

1.1.2本章的重点篇幅(1)教材P23的图1.24(四种逻辑数据模型的比较)。

(2)教材P25的图1.27(DB的体系结构)。

(3)教材P28的图1.29(DBMS的工作模式)。

(4)教材P33的图1.31(DBS的全局结构)。

1.2 教材中习题1的解答1.1 名词解释·逻辑数据:指程序员或用户用以操作的数据形式。

·物理数据:指存储设备上存储的数据。

·联系的元数:与一个联系有关的实体集个数,称为联系的元数。

·1:1联系:如果实体集E1中每个实体至多和实体集E2中的一个实体有联系,反之亦然,那么E1和E2的联系称为“1:1联系”。

·1:N联系:如果实体集E1中每个实体可以与实体集E2中任意个(零个或多个)实体有联系,而E2中每个实体至多和E1中一个实体有联系,那么E1和E2的联系是“1:N联系”。

·M:N联系:如果实体集E1中每个实体可以与实体集E2中任意个(零个或多个)实体有联系,反之亦然,那么E1和E2的联系称为“M:N联系”。

·数据模型:能表示实体类型及实体间联系的模型称为“数据模型”。

数据库系统实现课后习题答案

数据库系统实现课后习题答案

Solutions for Chapter 2Solutions for Section 2.1Solutions for Section 2.2Solutions for Section 2.3Solutions for Section 2.4Solutions for Section 2.5Solutions for Section 2.6Solutions for Section 2.1Exercise 2.1.1(a)Terabyte disks are about 100 times as large as ``1999'' disks. 100 is about 2^7, so there will have to be about seven doublings of disk size. According to Moore's law, that will take 10.5 years, so terabyte disks should be available in computer stores around 2010.Return to TopSolutions for Section 2.2Exercise 2.2.1(a)The disk has 10 * 10,000 = 100,000 tracks. The average track has 1000 * 512 = 512,000 bytes. Thus, the capacity is 51.2 gigabytes.Exercise 2.2.1(c)The maximum seek time occurs when the heads have to move across all the tracks. Thus, substitute 10,000 (really 9999) for n in the formula 1+.001n to get 11 milliseconds.Exercise 2.2.1(d)The maximum rotational latency is one full revolution. Since the disk rotates at 10,000 rpm, it takes 1/10000 of a minute, or 1/167 of a second to rotate, or about 6 milliseconds.Exercise 2.2.3First, we need to estabish the probability density function for the position of a random sector. Sincethese vary with the radius, the density at the inner edge is 3/7 the density of the outer edge, so the probability density looks like a trapezoid:** ** ** * 7/5* *3/5 * ** **********Call this function p(x) = 3/5 + 4x/5, with x varying from 0 to 1 and representing the fraction of the way from the inner to the outer edge that a sector is.Our question asks for the average over all x and y distributed by function p of the magnitude of x-y, that is:1 1INT INT p(x)p(y)|x-y| dx dy0 0Since the moves outward must equal the moves inward, we can eliminate the absolute-magnitude operator by doubling, and restricting to the case where x>y. That is, we compute:1 x2 INT INT p(x)p(y)(x-y) dx dy0 0If we substitute for p, we get1 x2 INT INT (3/5 + 4x/5)(3/5+4y/5)(x-y) dx dy0 0Now, we have only to expand terms, integrate first on y, then on x, to get the value of this integral: 121/375. That is, the average sector-to-sector move of the heads will traverse this fraction of the tracks, which is just slightly less than 1/3 of the tracks.Return to TopSolutions for Section 2.3Exercise 2.3.2(a)The relation occupies 250,000 blocks, and the sort takes 4 disk I/O's per block, or 1,000,000 diskI/O's. If the number of tuples were doubled, the relation would occupy twice as many blocks, so we would expect 2,000,000 disk I/O's. We should check that the 2-phase sort is still possible, but since doubling the size of the relation would require 40 sublists rather than 20, there will still be plenty of room in memory on the second pass.Exercise 2.3.2(c)Doubling the size of blocks reduces the number of disk I/O's needed to half, or 500,000. We might imagine that we could keep growing the size of blocks indefinitely, and thus reduce the number of disk I/O's to almost zero. In a sense we can, but there are limitations, including the fact that transfer time will eventually grow to dominate other aspects of latency, in which case counting disk I/O's fails to be a good measure of running time.Exercise 2.3.4Binary search requires probing the block in the middle of the 250,000 blocks, then the one in the middle of the first or second half, and so on, for log_2(250,000) = 18 probes, until we can narrow down the presence of the desired record on one block. Thus, we require 18 disk I/O's.Exercise 2.3.6Look ahead to the solution to Exercise 2.3.8. The formula derived there tells us that:1.Doubling B halves n. That is, the larger the block size, the smaller the relation we can sort withthe two-phase, multiway merge sort! Here is one good reason to keep block sizes modest.2.If we double R, then we halve the number of tuples we can sort, but that is no surprise, since thenumber of blocks occupied by the relation would then remain constant.3.If we double M we multiply by 4 the number of tuples we can sort.Exercise 2.3.8The number of sorted sublists s we need is s = nR/M. On the second phase we need one block for each sublist, plus one for the merged list. Thus, we require Bs < M. Substituting for s, we get nRB/M < M, or n < M^2/RB.Return to TopSolutions for Section 2.4Exercise 2.4.2Recall that the Megatron 747 has a transfer time (in milliseconds) of 0.5, and an average rotational latency of 7.8. If the average seek moves 1/3 of the way across 4096 tracks, the average seek time for the Megatron 747 is 1 + .002*(4096/3) = 3.7. Thus, the answer to part (a) is one block per 0.5 + 7.8 + 3.7 = 12 milliseconds, or 83 blocks per second, on each disk. Thus, the system can read 166 blocks per second.For a ``regular'' Megatron 747, the average latency is 0.5 + 7.8 + 6.5 = 14.8 milliseconds. However, if we have two, mirrored disks, each can be handling a request at the same time, or one read per 7.4 milliseconds. That gives us 135 blocks per second as the answer to (b).For part (c), restricting each disk to half the tracks means that if there is not always a queue of waiting requests (which slows the applications that the disk is supporting), then there might be two requests for the same half of the disk, in which case one disk is idle and a request waits.Exercise 2.4.3(a)Suppose that there are n requests waiting on each pass in the steady state. Then the time taken for a pass of the elevator algorithm is:1.0.5n for the transfers.2.7.8n for the rotational latencies.3.n + 16.4 for the seek times. To see the latter, notice that the head must start n times, whichaccounts for the first term, and total travel is 8192 tracks, which accounts for the second term, at the Megatron 747's rate of 500 tracks per millisecond.Let the time taken for a pass be t. Then 0.5n + 7.8n + n +16.4 = t. Also, during time t, another n requests must arrive, and they arrive one every A milliseconds. Thus, t = An.We can solve these two equations for n in terms of A; it is n = 16.4/(A - 9.3). The answer we want is t, the time to perform the pass. But t = An = 16.4A/(A - 9.3).Exercise 2.4.4Think of the requests as a random sequence of the integers 1 through 4. This sequence can be divided up into segments that do not contain two of the same integer, in a greedy way. For example, the sequence 123142342431 would be divided into 123, 1423, 42, and 31. The disks are serving all the requests from one segment, and each request is generated and starts at about the same time. When a segment is finished, the waiting request begins, along with other requests for other disks that are, by our assumption, generated almost immediately and thus finish at about the same time.The question is thus: if I choose numbers 1, 2, 3, and 4 at random, how many choices, on the average, can I make without a repeat? The cases are:1.1/4 of the time we get an immediate repeat on the second choice, and the length is therefore 1.2.(3/4)(1/2) = 3/8 of the time we get our first repeat at third number, and the length is 2.3.(3/4)(1/2)(3/4) = 9/32 of the time we get our first repeat at the fourth number, and our length is3.4.The remaining fraction of the time, 3/32, we get four different numbers, and our length is 4. The average length is therefore: (1/4)*1 + (3/8)*2 + (9/32)*3 + (3/32)*4 = 71/32.Return to TopSolutions for Section 2.5Exercise 2.5.1(a)There are five 1's, which is odd, so the parity bit is 1.Return to TopSolutions for Section 2.6Exercise 2.6.2To compute the mean time to failure, we can compute the probability that the system fails in a given year. The MTTF will be the inverse of that probability. Note that there are 8760 hours in a year.a) The system fails if the second disk fails while the first is being repaired. The probabiliy of afailure in a year is 2F. The probability that the second disk will fail during the H hours that theother is being prepared is H/8760. Thus, the probability of a failure in any year is 2FH/8760, and the MTTF is 4380/FHb) The system loses data if there are three disk crashes within an H hour period. The probabilityof any one disk failing in a year is NF. If so, there are (N-1)(N-2)/2 pairs of other disks thatcould fail within an H hour period, and the chance that any one of them will do so is FH/8760.Thus, the probability of two additional disk failures is (N-1)(N-2)F^2H^2/(2*8760^2), orapproximately (NFH)^2/1.5*10^8. The MTTF is the inverse of this probability.Exercise 2.6.4(a)01010110.Exercise 2.6.5(a)01010110. Notice that this question calls for the same computation as Exercise 2.6.4(a), or at least it would have, except for the typo in the third ``block,'' where 0011011 should have been 00111011.Exercise 2.6.8(a)In the matrix of Fig. 2.17, we see that columns 1 and 7 differ in both the first and second rows. In each case, column 1 has bit 1 and column 7 has bit 0. Let's use the first row to recover disk 1. That step requires us to take the modulo-2 sum of disks 2, 3, and 5, the other disks where row 1 has bit 1.Next, we use row 3, the only row where column 7 has a 1, to recover disk 7 by taking the modulo-2 sum of disks 1, 3, and 4.Exercise 2.6.12The parity checks of disks 9 and 10 can be represented by the matrix1 1 1 1 0 0 0 0 1 0 00 0 0 0 1 1 1 1 0 1 0Before we add a third row representing the parity check of disk 11, we can recover from two disk failures if and only if the two disks have different columns (except for disk 11, which has only 0's in its column). We'll surely add a 1 in column 11. So far, there are five columns with 1,0 (columns 1, 2, 3, 4, and 9) and five columns with 0,1 (columns 5, 6, 7, 8, and 10). The best we can do is break each of these groups 3-and-2, to maximize the number of pairs of disks that no longer have identical columns. Thus, we can make disk 11 be a parity check on any two or three of the first group and any two or three of the second group. An example would be to make disk 11 be a parity check on columns 3 through 6, but there are many other correct answers.Return to Top。

数据库课后练习及标准答案

数据库课后练习及标准答案

数据库课后练习及标准答案————————————————————————————————作者:————————————————————————————————日期:第一章:一、单选题1.以下的英文缩写中表示数据库管理系统的是( B)。

A. DB B.DBMS C.DBA D.DBS2.数据库管理系统、操作系统、应用软件的层次关系从核心到外围分别是(B )。

A. 数据库管理系统、操作系统、应用软件B. 操作系统、数据库管理系统、应用软件C. 数据库管理系统、应用软件、操作系统D. 操作系统、应用软件、数据库管理系统3.DBMS是(C )。

A. 操作系统的一部分B.一种编译程序 C.在操作系统支持下的系统软件 D.应用程序系统4.数据库系统提供给用户的接口是(A )。

A.数据库语言 B.过程化语言 C.宿主语言D.面向对象语5.(B )是按照一定的数据模型组织的,长期存储在计算机内,可为多个用户共享的数据的聚集。

A.数据库系统 B.数据库C.关系数据库D.数据库管理系统6. ( C)处于数据库系统的核心位置。

A.数据模型 B.数据库C.数据库管理系统D.数据库管理员7.( A)是数据库系统的基础。

A.数据模型B.数据库C.数据库管理系统D.数据库管理员8.( A)是数据库中全部数据的逻辑结构和特征的描述。

A.模式B.外模式 C.内模式 D.存储模式9.(C )是数据库物理结构和存储方式的描述。

A.模式 B.外模式 C.内模式D.概念模式10.( B)是用户可以看见和使用的局部数据的逻辑结构和特征的描述》 A.模式B.外模式C.内模式D.概念模式11.有了模式/内模式映像,可以保证数据和应用程序之间( B)。

A.逻辑独立性B.物理独立性C.数据一致性D.数据安全性12.数据管理技术发展阶段中,文件系统阶段与数据库系统阶段的主要区别之一是数据库系统( B)。

A.有专门的软件对数据进行管理B.采用一定的数据模型组织数据C.数据可长期保存D.数据可共享13.关系数据模型通常由3部分组成,它们是(B )。

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

6.1.2如果OUTPUT动作顺序恰当,即使在事务执行过程中发生故障,一致性仍能得到保持。

6.2.3答案1若题目是:<START U>; <U,A,10>; <START T> ….则答案是a)首先扫描日志,发现事务T和U都未commit,将其连接到未完成事务列.按照未完成事务列,从后往前逐步扫描日志并执行undo操作,按照<U,A,10>将磁盘中A值写为10,将<ABORT T>和<ABORT U>写入日志中并刷新日志。

b)首先扫描日志,发现事务T已经commit,将其连接到已完成事务列,事务U未完成,将其连接到未完成事务列。

按照未完成事务列,从后往前扫描日志执行undo操作,按照<U,C,30>将磁盘中C值写为30,<U,A,10>将磁盘A值写为10。

将<ABORT U>写入日志中并刷新日志。

c)首先扫描日志,发现事务T已经commit,将其连接到已完成事务列,事务U未完成,将其连接到未完成事务列。

按照未完成事务列从后往前扫描日志执行undo操作,按照<U,E,50>将磁盘中E值写为50,<U,C,30>将磁盘中C值写为30,<U,A,10>将磁盘A值写为10。

将<ABORT U>写入日志中并刷新日志。

d)首先扫描日志,发现事务T、U已经commit,将其连接到已完成列,未完成列为空,不做任何操作。

答案2a) <START T>事务T、U未提交,要被撤销。

向后扫描日志,遇到记录<U,A,10>,于是将A在磁盘上的值存为10。

最后,记录<ABORT U>和<ABORT T>被写到日志中且日志被刷新。

b) <COMMIT T>事务T已提交,U未提交,要被撤销。

向后扫描日志,首先遇到记录<U,C,30>,于是将C在磁盘上的值存为30。

接着遇到记录<U,A,10>,并将A在磁盘上的值置为10。

最后,记录<ABORT U>被写到日志中且日志被刷新。

c) <U,E,50>事务T已提交,U未提交,要被撤销。

向后扫描日志,首先遇到记录<U,E,50>,将E在磁盘上的值存为50。

接着遇到记录<U,C,30>,于是将C在磁盘上的值存为30。

再遇到记录<U,A,10>,并将A在磁盘上的值置为10。

最后,记录<ABORT U>被写到日志中且日志被刷新。

d) <COMMIT U>事务T、U均被提交。

什么都不做。

6.2.46.2.7a)当前活跃的事务只有S,日志记录为<START CKPT(S)>,所以在<COMMIT S>之后写入<END CKPT>记录。

如果故障发生在<END CKPT>记录之后,那么我们可以扫描直到下一个<START CKPT(S)>记录停止。

如果故障发生在<COMMIT S>之前,那么我们要回溯到<START S>。

b) 当前活跃的事务只有T,日志记录为<START CKPT(T)>,所以在<COMMIT T>之后写入<END CKPT>记录。

如果故障发生在<END CKPT>记录之后,那么我们可以向后扫描直到下一个<START CKPT(T)>记录停止。

如果故障发生在<COMMIT T>之前,那么我们要回溯到<START T>。

c)当前活跃的事务有T和U,日志记录为<START CKPT(T,U)>,所以在<COMMIT T>之后写入<END CKPT>记录。

如果故障发生在<END CKPT>记录之后,那么我们可以向后扫描直到下一个<START CKPT(T,U)>记录停止。

如果故障发生在<COMMIT T>之前,那么我们要回溯到<START T>。

d)当前活跃的事务有T、U和V,日志记录为<START CKPT(T,U,V)>,所以在<COMMIT V>之后写入<END CKPT>记录。

如果故障发生在<END CKPT>记录之后,那么我们可以向后扫描直到下一个<START CKPT(T,U,V)>记录停止。

如果故障发生在<COMMIT V>之前,那么我们要回溯到<START T>。

e)当前活跃的事务有T和V,日志记录为<START CKPT(T,V)>,所以在<COMMIT V>之后写入<END CKPT>记录。

如果故障发生在<END CKPT>记录之后,那么我们可以向后扫描直到下一个<START CKPT(T,V)>记录停止。

如果故障发生在<COMMIT V>之前,那么我们要回溯到<START T>6.3.2a)当前活跃的事务只有S,日志记录为<START CKPT(S)>,所以在<COMMIT S>之前写入<END CKPT>记录。

如果崩溃发生在<END CKPT>记录之后,那么在日志中只要回溯到<START S>。

如果崩溃发生在<END CKPT>记录之前,我们必须向后搜索到倒数第二个START CKPT记录并得到其活跃事务列表。

在本题中没有前一检查点,因而必须一直走到日志的开头,确定没有已提交的事务。

b) 当前活跃的事务只有T,日志记录为<START CKPT(T)>,所以在<COMMIT T>之前写入<END CKPT>记录。

如果崩溃发生在<END CKPT>记录之后,那么在日志中只要回溯到<START T>。

如果崩溃发生在<END CKPT>记录之前,我们必须向后搜索到倒数第二个START CKPT记录并得到其活跃事务列表。

在本题中没有前一检查点,因而必须一直走到日志的开头,确定已提交的事务只有S,重复其动作<S,A,60>,并在恢复后将记录<ABORT T>写入日志中。

c)当前活跃的事务有T和U,日志记录为<START CKPT(T,U)>,所以在<COMMIT U>之前写入<END CKPT>记录。

如果崩溃发生在<END CKPT>记录之后,那么在日志中只要回溯到<START T>。

如果崩溃发生在<END CKPT>记录之前,我们必须向后搜索到倒数第二个START CKPT记录并得到其活跃事务列表。

在本题中没有前一检查点,因而必须一直走到日志的开头,确定已提交的事务只有S,重复其动作<S,A,60>,并在恢复后将记录<ABORT T>和<ABORT U>写入日志中。

d)当前活跃的事务有T、U和V,日志记录为<START CKPT(T,U,V)>,所以在<COMMIT U>之前写入<END CKPT>记录。

如果崩溃发生在<END CKPT>记录之后,那么在日志中只要回溯到<START T>。

如果崩溃发生在<END CKPT>记录之前,我们必须向后搜索到倒数第二个START CKPT记录并得到其活跃事务列表。

在本题中没有前一检查点,因而必须一直走到日志的开头,确定已提交的事务只有S,重复其动作<S,A,60>,并在恢复后将记录<ABORT T> 、<ABORT U>和<ABORT V>写入日志中。

e)当前活跃的事务有T和V,日志记录为<START CKPT(T,V)>,所以在<COMMIT T>之前写入<END CKPT>记录。

如果崩溃发生在<END CKPT>记录之后,那么在日志中只要回溯到<START T>。

如果崩溃发生在<END CKPT>记录之前,我们必须向后搜索到倒数第二个START CKPT记录并得到其活跃事务列表。

在本题中没有前一检查点,因而必须一直走到日志的开头,确定已提交的事务有S和U,重复其动作<S,A,60>、<U,B,20>、<U,D,40>,并在恢复后将记录<ABORT T>和<ABORT V>写入日志中。

6.4.2答案1:a)首先扫描日志,发现事务U、T均未commit,将其连接到未完成列。

按照未完成列,从后往前逐步扫描日志并执行undo操作,按照<U,A,10,11>将磁盘中A值写为10.b)首先扫描日志,发现事务T已为commit而U未commit,故将T连接到已完成列而U连接到未完成列。

按照未完成列,从后往前扫描日志,按照<U,C,30,31>将磁盘中C写为30,<U,A,10,11>将磁盘中A值写为10。

按照已完成列,从前往后扫描日志,按照<T,B,20,21>将磁盘中B写为21,<T,D,40,41>将磁盘中D写为41.c) 最后一条记录为<U,E,50,51>这时我们为E往磁盘上写入值51,但是崩溃在<COMMIT U>记录到达前发生,则E在磁盘上的值为50。

d) 最后一条记录为<COMMIT U>,这时U被认为是已提交的事务。

我们为E往磁盘上写入值51,E 已经具有值51。

答案2a) <START T> 事务U未提交,回滚U(从后往前),A的值置为10。

在日志中写入<ABORT U>记录并刷新日志。

b) <COMMIT T> 事务T已提交,重做T,将B的值置为21,D的值置为41。

事务U未提交,回滚U(从后往前),将C的值置为30,A的值置为10。

在日志中写入<ABORT U>记录并刷新日志。

c) <U,E,50,51> 事务T已提交,重做T,将B的值置为21,D的值置为41。

事务U未提交,回滚U(从后往前),将E的值置为50,C的值置为30,A的值置为10。

在日志中写入<ABORT U>记录并刷新日志。

相关文档
最新文档