数据库系统概念第六版课后习题部分答案2s

合集下载

数据库系统原理教程课后习题答案

数据库系统原理教程课后习题答案

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

答:( l )数据( Data):描述事物得符号记录称为数据。

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

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

解析在现代计算机系统中数据得概念就是广义得。

早期得计算机系统主要用于科学计算,处理得数据就是整数、实数、浮点数等传统数学中得数据。

现代计算机能存储与处理得对象十分广泛,表示这些对象得数据也越来越复杂。

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

500 这个数字可以表示一件物品得价格就是500元,也可以表示一个学术会议参加得人数有500 人,还可以表示一袋奶粉重500 克。

(2)数据库( DataBase,简称DB) :数据库就是长期储存在计算机内得、有组织得、可共享得数据集合。

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

( 3 )数据库系统(DataBas。

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

解析数据库系统与数据库就是两个概念。

数据库系统就是一个人一机系统,数据库就是数据库系统得一个组成部分。

但就是在日常工作中人们常常把数据库系统简称为数据库。

希望读者能够从人们讲话或文章得上下文中区分“数据库系统”与“数据库”,不要引起混淆。

( 4 )数据库管理系统( DataBase Management sytem,简称DBMs ):数据库管理系统就是位于用户与操作系统之间得一层数据管理软件,用于科学地组织与存储数据、高效地获取与维护数据。

DBMS 得主要功能包括数据定义功能、数据操纵功能、数据库得运行管理功能、数据库得建立与维护功能。

解析DBMS 就是一个大型得复杂得软件系统,就是计算机中得基础软件。

目前,专门研制DBMS 得厂商及其研制得DBM S产品很多。

数据库系统课后习题及答案

数据库系统课后习题及答案

数据库系统课后习题及答案第1章绪论习题参考答案1、试述数据、数据库、数据库管理系统、数据库系统的概念。

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

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

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

(8、9、10页)答:1)数据结构化是数据库与文件系统的根本区别。

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

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

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

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

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

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

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

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

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

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

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

数据库系统概念第六版课后习题部分答案2s

数据库系统概念第六版课后习题部分答案2s

C H A P T E R2Introduction to the Relational ModelPractice Exercises2.1Consider the relational database of Figure??.What are the appropriateprimary keys?Answer:The answer is shown in Figure2.1,with primary keys under-lined.2.2Consider the foreign key constraint from the dept name attribute of in-structor to the department relation.Give examples of inserts and deletes tothese relations,which can cause a violation of the foreign key constraint.Answer:•Inserting a tuple:(10111,Ostrom,Economics,110,000)into the instructor table,where the department table does not have thedepartment Economics,would violate the foreign key constraint.•Deleting the tuple:(Biology,Watson,90000)from the department table,where at least one student or instructortuple has dept name as Biology,would violate the foreign key con-straint.employee(person name,street,city)works(person name company name,salary)company(company name,city)Figure2.1Relational database for Practice Exercise2.1.12Chapter2Introduction to the Relational Model2.3Consider the time slot relation.Given that a particular time slot can meetmore than once in a week,explain why day and start time are part of theprimary key of this relation,while end time is not.Answer:The attributes day and start time are part of the primary keysince a particular class will most likely meet on several different days,and may even meet more than once in a day.However,end time is notpart of the primary key since a particular class that starts at a particulartime on a particular day cannot end at more than one time.2.4In the instance of instructor shown in Figure??,no two instructors havethe same name.From this,can we conclude that name can be used as asuperkey(or primary key)of instructor?Answer:No.For this possible instance of the instructor table the namesare unique,but in general this may not be always the case(unless theuniversity has a rule that two instructors cannot have the same name,which is a rather unlikey scenario).2.5What is the result offirst performing the cross product of student andadvisor,and then performing a selection operation on the result with thepredicate s id=ID?(Using the symbolic notation of relational algebra,this query can be written as␴s id=I D(student×advisor).)Answer:The result attributes include all attribute values of studentfollowed by all attributes of advisor.The tuples in the result are asfollows.For each student who has an advisor,the result has a rowcontaining that students attributes,followed by an s id attribute identicalto the students ID attribute,followed by the i id attribute containing theID of the students advisor.Students who do not have an advisor will not appear in the result.Astudent who has more than one advisor will appear a correspondingnumber of times in the result.2.6Consider the following expressions,which use the result of a relationalalgebra operation as the input to another operation.For each expression,explain in words what the expression does.a.␴year≥2009(takes)1studentb.␴year≥2009(takes1student)c. ID,name,course id(student1takes)Answer:a.For each student who takes at least one course in2009,displaythe students information along with the information about whatcourses the student took.The attributes in the result are:ID,name,dept name,tot cred,course id,section id,semester,year,gradeb.Same as(a);selection can be done before the join operation.c.Provide a list of consisting ofExercises3ID,name,course idof all students who took any course in the university.2.7Consider the relational database of Figure??.Give an expression in therelational algebra to express each of the following queries:a.Find the names of all employees who live in city“Miami”.b.Find the names of all employees whose salary is greater than$100,000.c.Find the names of all employees who live in“Miami”and whosesalary is greater than$100,000.Answer:a. name(␴city=“Miami”(employee))b. name(␴salary>100000(employee))c. name(␴city=“Miami”∧salary>100000(employee))2.8Consider the bank database of Figure??.Give an expression in therelational algebra for each of the following queries.a.Find the names of all branches located in“Chicago”.b.Find the names of all borrowers who have a loan in branch“Down-town”.Answer:a. branch name(␴branch city=“Chicago”(branch))b. customer name(␴branch name=“Downtown”(borro w er1loan))。

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

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

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

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

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

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

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

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

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

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

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

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

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

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

使用数据库系统的好处很多,例如可以大大提高应用开发的效率,方便用户的使用,减轻数据库系统管理人员维护的负担等。

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

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

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

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

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

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

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

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

数据库系统概念 习题答案

数据库系统概念 习题答案

数据库系统概念习题答案数据库系统概念习题答案数据库系统概念是计算机科学中的重要课程之一,它涉及到了数据库的设计、管理和应用等方面。

在学习这门课程时,习题是检验自己掌握程度的重要途径。

下面我将为大家提供一些数据库系统概念课程中常见习题的答案,希望能对大家的学习有所帮助。

1. 什么是数据库系统?答:数据库系统是一个能够存储、管理和操作大量结构化数据的软件系统。

它由数据库、数据库管理系统(DBMS)和应用程序组成,能够提供数据的安全性、一致性和可靠性。

2. 数据库系统有哪些特点?答:数据库系统具有以下特点:- 数据共享:多个用户可以同时访问和共享数据库中的数据。

- 数据独立性:数据库系统能够将数据的逻辑表示与物理表示相分离,使得对数据的操作不受物理存储方式的影响。

- 数据一致性:数据库系统能够保证数据的一致性,即数据的更新和修改操作能够满足事务的原子性、一致性、隔离性和持久性要求。

- 数据持久性:数据库系统能够将数据永久地存储在磁盘等非易失性存储介质中,以防止数据丢失。

3. 什么是数据库模式?答:数据库模式是数据库中数据的逻辑结构和特征的描述。

它包括实体、属性和关系等元素的定义,用于描述数据库中各个实体之间的关系和约束条件。

4. 数据库系统的架构有哪些?答:数据库系统的架构主要包括三层:外模式(用户视图)、概念模式和内模式。

- 外模式:也称为用户视图,是用户对数据库中数据的逻辑视图,它定义了用户能够看到和操作的数据。

- 概念模式:也称为全局模式,是数据库中所有数据的逻辑视图,它定义了数据的整体结构和组织方式。

- 内模式:也称为物理模式,是数据库中数据在物理存储介质上的表示方式,它定义了数据在磁盘上的存储结构和访问方法。

5. 数据库设计的步骤有哪些?答:数据库设计的步骤主要包括需求分析、概念设计、逻辑设计和物理设计。

- 需求分析:明确用户的需求和要求,确定数据库的功能和性能需求。

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

使用数据库系统的好处很多,例如可以大大提高应用开发的效率,方便用户的使用,减轻数据库系统管理人员维护的负担等。

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

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

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

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

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

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

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

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

数据库系统概念(databasesystemconcepts)英文第六版课后练习题答案第8章

数据库系统概念(databasesystemconcepts)英文第六版课后练习题答案第8章

数据库系统概念(databasesystemconcepts)英文第六版课后练习题答案第8章C H A P T E R8Relational Database DesignExercises8.1Suppose that we decompose the schema R=(A,B,C,D,E)into(A,B,C)(A,D,E).Show that this decomposition is a lossless-join decomposition if thefollowing set F of functional dependencies holds:A→BCCD→EB→DE→AAnswer:A decomposition{R1,R2}is a lossless-join decomposition ifR1∩R2→R1or R1∩R2→R2.Let R1=(A,B,C),R2=(A,D,E),and R1∩R2=A.Since A is a candidate key(see Practice Exercise8.6),Therefore R1∩R2→R1.8.2List all functional dependencies satis?ed by the relation of Figure8.17.Answer:The nontrivial functional dependencies are:A→B and C→B,and a dependency they logically imply:AC→B.There are 19trivial functional dependencies of the form?→?,where.C does not functionally determine A because the?rst and third tuples havethe same C but different A values.The same tuples also showB does notfunctionally determine A.Likewise,A does not functionally determineC because the?rst two tuples have the same A value and different Cvalues.The same tuples also show B does not functionally determine C.8.3Explain how functional dependencies can be used to indicate the fol-lowing:910Chapter8Relational Database DesignA one-to-one relationship set exists between entity sets student andinstructor.A many-to-one relationship set exists between entity sets studentand instructor.Answer:Let Pk(r)denote the primary key attribute of relation r.The functi onal dependencies Pk(student)→Pk(instructor)and Pk(instructor)→Pk(student)indicate a one-to-one relationshipbecause any two tuples with the same value for student must havethe same value for instructor,and any two tuples agreeing on instructor must have the same value for student.The functional dependency Pk(student)→Pk(instructor)indicates amany-to-one relationship since any student value which isrepeatedwill have the same instructor value,but many student values mayhave the same instructor value.8.4Use Armstrong’s axioms to prove the soundness of the union rule.(Hint:Use the augmentation rule to show that,if?→?,then?→??.Apply theaugmentation rule again,using?→?,and then apply the transitivityrule.)Answer:To prove that:if?→?and?→?then?→??Following the hint,we derive:→?given→??augmentation rule→??union of identical sets→?given→??augmentation rule→??transitivity rule and set union commutativity8.5Use Armstrong’s axioms to prove the soundness of the pseudotransitiv-ity rule.Answer:Pr oof using Armstrong’s axioms of the Pseudotransitivity Rule:if?→?and??→?,then??→?.→?given→??augmentation rule and set union commutativity→?given→?transitivity rule8.6Compute the closure of the following set F of functional dependenciesfor relation schema R=(A,B,C,D,E).Exercises 11A →BCCD →EB →DE →AList the candidate keys for R .Answer:Note:It is not reasonable to expect students to enumerate all of F +.Some shorthand representation of the result should be acceptable as long as the nontrivial members of F +are found.Starting with A →BC ,we can conclude:A →B and A →C .Since A →B and B →D ,A →D (decomposition,transitive)Since A →C D and C D →E ,A →E (union,decom-position,transi-tive)Since A →A ,we have (re?exive)A →ABC DE from the above steps (union)Since E →A ,E →ABC DE (transitive)Since C D →E ,C D →ABC DE (transitive)Since B →D and BC →C D ,BC →ABC DE (augmentative,transitive)Also,C →C ,D →D ,B D →D ,etc.Therefore,any functional dependency with A ,E ,BC ,or C D on the left hand side of the arrow is in F +,no matter which other attributes appear in the FD.Allow *to represent any set of attributes in R ,then F +is B D →B ,B D →D ,C →C ,D →D ,B D →B D ,B →D ,B →B ,B →B D ,and all FDs of the form A ?→?,BC ?→?,C D ?→?,E ?→?where ?is any subset of {A ,B ,C ,D ,E }.The candidate keys are A ,BC ,C D ,and E .8.7Using the functional dependencies of Practice Exercise8.6,compute thecanonical cover F c .Answer:The given set of FDs F is:-A →BCCD →EB →DE →AThe left side of each FD in F is unique.Also none of the attributes in the left side or right side of any of the FDs is extraneous.Therefore the canonical cover F c is equal to F .12Chapter8Relational Database Design8.8Consider the algorithm in Figure8.18to compute?+.Show that thisalgorithm is more ef?cient than the one presented in Figure8.8(Sec-tion8.4.2)and that it computes?+correctly.Answer:The algorithm is correct because:If A is added to result then there is a proof that?→A.T o see this,observe that?→?trivially so?is correctly part of result.IfA∈?is added to result there must be some FD?→?such that A∈?and?is already a subset of result.(Otherwise f dcountwould be nonzero and the if condition would be false.)A full proofcan be given by induction on the depth of recursion for an executionof addin,but such a proof can be expected only from students witha good mathematical background.If A∈?+,then A is eventually added to result.We prove this byinduction on the length of the proof of?→A using Armstrong’saxioms.First observe that if procedure addin is called with someargument?,all the attributes in?will be added to result.Also if aparticular FD’s fdcount becomes0,all the attributes in its tail willde?nitely be added to result.The base case of the proof,A∈??A∈?+,is obviously true b ecause the?rst call to addinhas the argument?.The inductive hypotheses is that if?→A canbe proved in n steps or less then A∈result.If there is a proof inn+1steps that?→A,then the last step was an application ofeither re?exivity,augmentation or transiti vity on a fact?→?proved in n or fewer steps.If re?exivity or augmentation was usedin the(n+1)st step,A must have been in result by the end of the n thstep itself.Otherwise,by the inductive hypothesis??result.Therefore the dependency used in proving?→?,A∈?willhave f dcount set to0by the end of the n th step.Hence A will beadded to result.To see that this algorithm is more ef?cient than the one presented inthe chapter note that we scan each FD once in the main program.Theresulting array a ppears has size proportional to the size ofthe givenFDs.The recursive calls to addin result in processing linear in the sizeof a ppears.Hence the algorithm has time complexity which is linear inthe size of the given FDs.On the other hand,the algorithm given in thetext has quadratic time complexity,as it may perform the loop as manytimes as the number of FDs,in each loop scanning all of them once.8.9Given the database schema R(a,b,c),and a relation r on the schema R,write an SQL query to test whether the functional dependency b→cholds on relation r.Also write an SQL assertion that enforces the func-tional dependency.Assume that no null values are present.(Althoughpart of the SQL standard,such assertions are not supported by anydatabase implementation currently.)Answer:Exercises13a.The query is given below.Its result is non-empty if and only ifb→c does not hold on r.select bfrom rgroup by bhaving count(distinct c)>1b.create assertion b to c check(not exists(select bfrom rgroup by bhaving count(distinct c)>1))8.10Our discussion of lossless-join decomposition implicitly assumed thatattributes on the left-hand side of a functional dependency cannot take on null values.What could go wrong on decomposition,if this property is violated?Answer:The natural join operator is de?ned in terms of the cartesian product and the selection operator.The selection operator,gives unknown for any query on a null value.Thus,the natural join excludes all tuples with null values on the common attributes from the?nal result.Thus, the decomposition would be lossy(in a manner different from the usual case of lossy decomposition),if null values occur in the left-hand side of the functional dependency used to decompose the relation.(Null values in attributes that occur only in the right-hand side of the functional dependency do not cause any problems.)8.11In the BCNF decomposition algorithm,suppose you usea functional de-pendency?→?to decompose a relation schema r(?,?,?)into r1(?,?) and r2(?,?).a.What primary and foreign-key constraint do you expect toholdon the decomposed relations?b.Give an example of an inconsistency that can arise due to anerroneous update,if the foreign-key constraint were not enforcedon the decomposed relations above.c.When a relation is decomposed into3NF using the algorithm inSection8.5.2,what primary and foreign key dependencies wouldyou expect will hold on the decomposed schema?14Chapter8Relational Database DesignAnswer:a.?should be a primary key for r1,and?should be the foreign keyfrom r2,referencing r1.b.If the foreign key constraint is not enforced,then a deletion of atuple from r1would not have a corresponding deletion from thereferencing tuples in r2.Instead of deleting a tuple from r,this would amount to simply setting the value of?to null in some tuples.c.For every schema r i(??)added to the schema because of a rule→?,?should be made the primary key.Also,a candidate key?for the original relation is located in some newly created relationr k,and is a primary key for that relation.Foreign key constraints are created as follows:for each relationr i created above,if the primary key attributes of r i also occur inany other relation r j,then a foreign key constraint is created fromthose attributes in r j,referencing(the primary key of)r i.8.12Let R1,R2,...,R n be a decomposition of schema U.Let u(U)be a rela-(u).Show thattion,and let r i= RIu?r11r21···1r nAnswer:Consider some tuple t in u.(u)implies that t[R i]∈r i,1≤i≤n.Thus,Note that r i= Rit[R1]1t[R2]1...1t[R n]∈r11r21...1r nBy the de?nition of natural join,t[R1]1t[R2]1...1t[R n]= ?(??(t[R1]×t[R2]×...×t[R n]))where the condition?is satis?ed if values of attributes with the samename in a tuple are equal and where?=U.The cartesian productof single tuples generates one tuple.The selection process is satis?edbecause all attributes with the same name must have the same valuesince they are projections from the same tuple.Finally,the projectionclause removes duplicate attribute names.By th e de?nition of decomposition,U=R1∪R2∪...∪R n,which meansthat all attributes of t are in t[R1]1t[R2]1...1t[R n].That is,t is equalto the result of this join.Since t is any arbitrary tuple in u,u?r11r21...1r n8.13Show that the decomposition in Practice Exercise8.1is not a dependency-preserving decomposition.Answer:The dependency B→D is not preserved.F1,the restrictionof F to(A,B,C)is A→ABC,A→AB,A→AC,A→BC,Exercises 15A →B ,A →C ,A →A ,B →B ,C →C ,AB →AC ,AB →ABC ,AB →BC ,AB →AB ,AB →A ,AB →B ,AB →C,AC (same as AB ),BC (same as AB ),ABC (same as AB ).F 2,the restriction of F to (C ,D ,E )is A →ADE ,A →AD ,A →AE ,A →DE ,A →A ,A →D ,A →E ,D →D ,E (same as A ),AD ,AE ,DE ,ADE (same as A ).(F 1∪F 2)+is easily seen not to contain B →D since the only F D in F 1∪F 2with B as the left side is B →B ,a trivial FD .We shall see in Practice Exercise 8.15that B →D is indeed in F +.Thus B →D is not preserved.Note that C D →ABC DE is also not preserved.A simpler argument is as follows:F 1contains no dependencies with D on the right side of the arrow.F 2contains no dependencies withB on the left side of the arrow.Therefore for B →D to be preserved theremustbe an FD B →?in F +1and ?→D in F +2(so B →D would follow by transitivity).Since the intersection of the two schemes isA ,?=A .Observe thatB →A is not in F +1since B +=B D .8.14Show that it is possible to ensure that a dependency-preserving decom-position into 3NF is a lossless-join decomposition by guaranteeing that at least one schema contains a candidate key for the schema being decom-posed.(Hint :Show that the join of all the projections onto the schemas of the decomposition cannot have more tuples than the original relation.)Answer:Let F be a set of functional dependencies that hold on a schema R .Let ?={R 1,R 2,...,R n }be a dependency-preserving 3NF decompo-sition of R .Let X be a candidate key for R .Consider a legal instance r of R .Let j = X (r )1 R 1(r )1 R 2(r ) (1)R n (r ).We want to prove that r =j .We claim that if t 1and t 2are two tuples in j such that t 1[X ]=t2[X ],then t 1=t 2.To prove this claim,we use the following inductive argument –Let F ′=F 1∪F 2∪...∪F n ,where each F i is the restriction of F to the schema R i in ?.Consider the use of the algorithm given in Figure 8.8to compute the closure of X under F ′.We use induction on the number of times that the f or loop in this algorithm is executed.Basis :In the ?rst step of the algorithm,result is assigned to X ,and hence given that t 1[X ]=t 2[X ],we know that t 1[result ]=t 2[result ]is true.?Induction Step :Let t 1[result ]=t 2[result ]be true at the end of thek th execution of the f or loop.Suppose the functionaldependency considered in the k +1th execution of the f or loop is ?→?,and that ??result .??result implies that t 1[?]=t 2[?]is true.The facts that ?→?holds for some attribute set Ri in ?,and that t 1[R i ]and t 2[R i ]are inR i (r )imply that t 1[?]=t 2[?]is also true.Since ?is now added to result by the algorithm,we know that t 1[result ]=t 2[result ]is true at theend of the k +1th execution of the f or loop.16Chapter8Relational Database DesignSince?is dependency-preserving and X is a key for R,all attributes in Rare in result when the algorithm terminates.Thus,t1[R]=t2[R]is true,that is,t1=t2–as claimed earlier.Our claim implies that the size of X(j)is equal to the size of j.Notealso that X(j)= X(r)=r(since X is a key for R).Thus we haveproved that the size of j equals that of /doc/826273026.htmling the result of PracticeExercise8.12,we know that r?j.Hence we conclude that r=j.Note that since X is trivially in3NF,?∪{X}is a dependency-preservinglossless-join decomposition into3NF.8.15Give an example of a relation schema R′and set F′of functional depen-dencies such that there are at least three distinct lossless-join decompo-sitions of R′into BCNF.Answer:Given the relation R′=(A,B,C,D)the set of functionaldependencies F′=A→B,C→D,B→C allows three distinctBCNF decompositions.R1={(A,B),(C,D),(B,C)}is in BCNF as isR2={(A,B),(C,D),(A,C)}R2={(A,B),(C,D),(A,C)}R3={(B,C),(A,D),(A,B)}8.16Let a prime attribute be one that appears in at least one candidate key.Let?and?be sets of attributes such that?→?holds,but?→?does not hold.Let A be an attribute that is not in?,is not in?,and forwhich?→A holds.We say that A is transitively dependent on?.Wecan restate our de?nition of3NF as follows:A relation schema R is in3NF with respect to a set F of functional dependencies if there are nononprime attributes A in R for which A is transitively dependent on akey for R.Show that this new de?nition is equivalent to the original one.Answer:Suppose R is in3NF according to the textbook de?nition.Weshow that it is in3NF according to the de?nition in the exercise.Let A bea nonprime attribute in R that is transitively dependent on a key?forR.Then there exists??R such that?→A,?→?,A∈?,A∈,and?→?does not hold.But then?→A violates the textbookde?nition of3NF sinceA∈?implies?→A is nontrivialSince?→?does not hold,?is not a superkeyA is not any candidate key,since A is nonprimeExercises17 Now we show that if R is in3NF according to the exercise de?nition,it is in3NF according to the textbook de?nition.Suppose R is not in3NF according the the textbook de?nition.Then there is an FD?→?that fails all three conditions.Thus→?is nontrivial.is not a superkey for R.Some A inis not in any candidate key.This implies that A is nonprime and?→A.Let?be a candidate key for R.Then?→?,?→?does not hold(since?is not a superkey), A∈?,and A∈?(since A is nonprime).Thus A is transitively dependent on?,violating the exercise de?nition.8.17A functional dependency?→?is called a partial dependency if thereis a proper subset?of?such that?→?.We say that?is partially dependent on?.A relation schema R is in second normal form(2NF)if each attribute A in R meets one of the following criteria:It appears in a candidate key.It is not partially dependent on a candidate key.Show that every3NF schema is in2NF.(Hint:Show that every partial dependency is a transitive dependency.)Answer:Referring to the de?nitions in Practice Exercise8.16,a relation schema R is said to be in3NF if there is no non-prime attribute A in R for which A is transitively dependent on a key forR.We can also rewrite the de?nition of2NF given here as:“A relation schema R is in2NF if no non-prime attribute A is partially dependent on any candidate key for R.”To prove that every3NF schema is in2NF,it suf?ces to show that if a non-prime attribute A is partially dependent on a candidate key?,thenA is also transitively dependent on the key?.Let A be a non-prime attribute in R.Let?be a candidate key for R.Suppose A is partially dependent on?.From the de?nition of a partial dependency,we know that for someproper subset?of?,?→A.Since,?→?.Also,?→?does not hold,sin ce?is acandidate key.Finally,since A is non-prime,it cannot be in either?or?.Thus we conclude that?→A is a transitive dependency.Hence we have proved that every3NF schema is also in2NF.8.18Give an example of a relation schema R and a set of dependencies suchthat R is in BCNF but is not in4NF.18Chapter8Relational Database DesignAnswer:R(A,B,C)A→→BExercises19result:=?;/*fdcount is an array whose i th element contains the number of attributes on the left side of the i th FD that arenot yet known to be in?+*/for i:=1to|F|dobeginlet?→?denote the i th FD;fdcount[i]:=|?|;end/*appears is an array with one entry for each attribute.The entry for attribute A is a list of integers.Each integeri on the list indicates that A appears on the left sideof the i th FD*/for each attribute A dobeginappears[A]:=NI L;for i:=1to|F|dobeginlet?→?denote the i th FD;if A∈?then add i to appears[A];endendaddin(?);return(result);procedure addin(?);for each attribute A in?dobeginif A∈result thenbeginresult:=result∪{A};for each element i of appears[A]dobeginfdcount[i]:=fdcount[i]?1;if fdcount[i]:=0thenbeginlet?→?denote the i th FD;addin(?);endendendendFigure8.18.An algorithm to compute?+.。

数据库系统概论部分答案

数据库系统概论部分答案

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

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

数据的种类有数字、文字、图形、图像、声音、正文等。

( 2 )数据库(DataBase ,简称DB ) :数据库是长期储存在计算机内的、有组织的、可共享的数据集合。

( 3 )数据库系统(DataBas 。

Sytem ,简称DBS ) :数据库系统是指在计算机系统中引入数据库后的系统构成,( 4 )数据库管理系统(DataBase Management sytem ,简称DBMs ) :数据库管理系统是位于用户与操作系统之间的一层数据管理软件,用于科学地组织和存储数据、高效地获取和维护数据。

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

答:( l )数据结构化数据库系统实现整体数据的结构化,这是数据库的主要特征之一,也是数据库系统与文件系统的本质区别。

( 2 )数据的共享性高,冗余度低,易扩充数据库的数据不再面向某个应用而是面向整个系统,因此可以被多个用户、多个应用以多种不同的语言共享使用。

( 3 )数据独立性高数据独立性包括数据的物理独立性和数据的逻辑独立性。

数据库管理系统的模式结构和二级映像功能保证了数据库中的数据具有很高的物理独立性和逻辑独立性。

( 4 )数据由DBMS 统一管理和控制数据库的共享是并发的共享,即多个用户可以同时存取数据库中的数据甚至可以同时存取数据库中同一个数据。

7. 什么是概念模型?试述概念模型的作用。

答:概念模型是现实世界到机器世界的一个中间层次,作用:用于信息世界的建模,是现实世界到信息世界的第一层抽象,数据库设计人员进行数据库设计的有力工具,也是数据库设计人员和用户之间进行交流的语言。

8.定义并解释概念模型中以下术语:实体,实体型,实体集,实体之间的联系答:实体:客观存在并可以相互区分的事物叫实体。

实体型:具有相同属性的实体具有相同的特征和性质,用实体名及其属性名集合来抽象和刻画同类实体,称为实体型。

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

数据库系统概念(database system concepts)英文第六版 课后练习题 答案 第19章

数据库系统概念(database system concepts)英文第六版 课后练习题 答案 第19章

C H A P T E R19Distributed DatabasesPractice Exercises19.1How might a distributed database designed for a local-area network differfrom one designed for a wide-area network?Answer:Data transfer on a local-area network(LAN)is much faster thanon a wide-area network(WAN).Thus replication and fragmentation willnot increase throughput and speed-up on a LAN,as much as in a WAN.But even in a LAN,replication has its uses in increasing reliability andavailability.19.2To build a highly available distributed system,you must know what kindsof failures can occur.a.List possible types of failure in a distributed system.b.Which items in your list from part a are also applicable to a central-ized system?Answer:a.The types of failure that can occur in a distributed system includei.Site failure.ii.Disk failure.munication failure,leading to disconnection of one or moresites from the network.b.Thefirst two failure types can also occur on centralized systems.19.3Consider a failure that occurs during2PC for a transaction.For each pos-sible failure that you listed in Practice Exercise19.2a,explain how2PCensures transaction atomicity despite the failure.Answer:A proof that2PC guarantees atomic commits/aborts inspite ofsite and link failures,follows.The main idea is that after all sites replywith a<ready T>message,only the co-ordinator of a transaction canmake a commit or abort decision.Any subsequent commit or abort by a12Chapter19Distributed Databasessite can happen only after it ascertains the co-ordinator’s decision,eitherdirectly from the co-ordinator,or indirectly from some other site.Let usenumerate the cases for a site aborting,and then for a site committing.a.A site can abort a transaction T(by writing an<abort T>log record)only under the following circumstances:i.It has not yet written a<ready T>log-record.In this case,theco-ordinator could not have got,and will not get a<ready T>or<commit T>message from this site.Therefore only an abortdecision can be made by the co-ordinator.ii.It has written the<ready T>log record,but on inquiry it foundout that some other site has an<abort T>log record.In thiscase it is correct for it to abort,because that other site wouldhave ascertained the co-ordinator’s decision(either directly orindirectly)before actually aborting.iii.It is itself the co-ordinator.In this case also no site could havecommitted,or will commit in the future,because commit deci-sions can be made only by the co-ordinator.b.A site can commit a transaction T(by writing an<commit T>logrecord)only under the following circumstances:i.It has written the<ready T>log record,and on inquiry it foundout that some other site has a<commit T>log record.In thiscase it is correct for it to commit,because that other site wouldhave ascertained the co-ordinator’s decision(either directly orindirectly)before actually committing.ii.It is itself the co-ordinator.In this case no other participatingsite can abort/would have aborted,because abort decisions aremade only by the co-ordinator.19.4Consider a distributed system with two sites,A and B.Can site A distin-guish among the following?•B goes down.•The link between A and B goes down.•B is extremely overloaded and response time is100times longer than normal.What implications does your answer have for recovery in distributedsystems?Answer:Site A cannot distinguish between the three cases until communicationhas resumed with site B.The action which it performs while B is inacces-sible must be correct irrespective of which of these situations has actuallyPractice Exercises3 occurred,and must be such that B can re-integrate consistently into the distributed system once communication is restored.19.5The persistent messaging scheme described in this chapter depends ontimestamps combined with discarding of received messages if they are too old.Suggest an alternative scheme based on sequence numbers instead of timestamps.Answer:We can have a scheme based on sequence numbers similar to the scheme based on timestamps.We tag each message with a sequence number that is unique for the(sending site,receiving site)pair.The num-ber is increased by1for each new message sent from the sending site to the receiving site.The receiving site stores and acknowledges a received message only if it has received all lower numbered messages also;the message is stored in the received-messages relation.The sending site retransmits a message until it has received an ack from the receiving site containing the sequence number of the transmitted message, or a higher sequence number.Once the acknowledgment is received,it can delete the message from its send queue.The receiving site discards all messages it receives that have a lower sequence number than the latest stored message from the sending site.The receiving site discards from received-messages all but the(number of the) most recent message from each sending site(message can be discarded only after being processed locally).Note that this scheme requires afixed(and small)overhead at the receiving site for each sending site,regardless of the number of messages received.In contrast the timestamp scheme requires extra space for every message.The timestamp scheme would have lower storage overhead if the number of messages received within the timeout interval is small compared to the number of sites,whereas the sequence number scheme would have lower overhead otherwise.19.6Give an example where the read one,write all available approach leadsto an erroneous state.Answer:Consider the balance in an account,replicated at N sites.Let the current balance be$100–consistent across all sites.Consider two trans-actions T1and T2each depositing$10in the account.Thus the balance would be$120after both these transactions are executed.Let the transac-tions execute in sequence:T1first and then T2.Let one of the sites,say s, be down when T1is executed and transaction t2reads the balance from site s.One can see that the balance at the primary site would be$110at the end.19.7Explain the difference between data replication in a distributed systemand the maintenance of a remote backup site.Answer:In remote backup systems all transactions are performed at the primary site and the data is replicated at the remote backup site.The4Chapter19Distributed Databasesremote backup site is kept synchronized with the updates at the primarysite by sending all log records.Whenever the primary site fails,the remotebackup site takes over processing.The distributed systems offer greater availability by having multiplecopies of the data at different sites whereas the remote backup systemsoffer lesser availability at lower cost and execution overhead.In a distributed system,transaction code runs at all the sites whereas ina remote backup system it runs only at the primary site.The distributedsystem transactions follow two-phase commit to have the data in con-sistent state whereas a remote backup system does not follow two-phasecommit and avoids related overhead.19.8Give an example where lazy replication can lead to an inconsistent databasestate even when updates get an exclusive lock on the primary(master)copy.Answer:Consider the balance in an account,replicated at N sites.Let thecurrent balance be$100–consistent across all sites.Consider two trans-actions T1and T2each depositing$10in the account.Thus the balancewould be$120after both these transactions are executed.Let the trans-actions execute in sequence:T1first and then T2.Suppose the copy of thebalance at one of the sites,say s,is not consistent–due to lazy replicationstrategy–with the primary copy after transaction T1is executed and lettransaction T2read this copy of the balance.One can see that the balanceat the primary site would be$110at the end.19.9Consider the following deadlock-detection algorithm.When transactionT i,at site S1,requests a resource from T j,at site S3,a request message withtimestamp n is sent.The edge(T i,T j,n)is inserted in the local wait-forgraph of S1.The edge(T i,T j,n)is inserted in the local wait-for graph ofS3only if T j has received the request message and cannot immediatelygrant the requested resource.A request from T i to T j in the same site ishandled in the usual manner;no timestamps are associated with the edge(T i,T j).A central coordinator invokes the detection algorithm by sendingan initiating message to each site in the system.On receiving this message,a site sends its local wait-for graph to the coordinator.Note that such a graph contains all the local information thatthe site has about the state of the real graph.The wait-for graph reflectsan instantaneous state of the site,but it is not synchronized with respectto any other site.When the controller has received a reply from each site,it constructs a graph as follows:•The graph contains a vertex for every transaction in the system.•The graph has an edge(T i,T j)if and only if:◦There is an edge(T i,T j)in one of the wait-for graphs.Practice Exercises5◦An edge(T i,T j,n)(for some n)appears in more than one wait-forgraph.Show that,if there is a cycle in the constructed graph,then the system isin a deadlock state,and that,if there is no cycle in the constructed graph,then the system was not in a deadlock state when the execution of thealgorithm began.Answer:Let us say a cycle T i→T j→···→T m→T i exists in the graphbuilt by the controller.The edges in the graph will either be local edgesof the from(T k,T l)or distributed edges of the form(T k,T l,n).Each localedge(T k,T l)definitely implies that T k is waiting for T l.Since a distributededge(T k,T l,n)is inserted into the graph only if T k’s request has reachedT l and T l cannot immediately release the lock,T k is indeed waiting for T l.Therefore every edge in the cycle indeed represents a transaction waitingfor another.For a detailed proof that this imlies a deadlock refer to Stuartet al.[1984].We now prove the converse implication.As soon as it is discovered thatT k is waiting for T l:a.a local edge(T k,T l)is added if both are on the same site.b.The edge(T k,T l,n)is added in both the sites,if T k and T l are ondifferent sites.Therefore,if the algorithm were able to collect all the local wait-for graphsat the same instant,it would definitely discover a cycle in the constructedgraph,in case there is a circular wait at that instant.If there is a circu-lar wait at the instant when the algorithm began execution,none of theedges participating in that cycle can disappear until the algorithmfin-ishes.Therefore,even though the algorithm cannot collect all the localgraphs at the same instant,any cycle which existed just before it startedwill anyway be detected.19.10Consider a relation that is fragmented horizontally by plant number:employee(name,address,salary,plant number)Assume that each fragment has two replicas:one stored at the New Yorksite and one stored locally at the plant site.Describe a good processingstrategy for the following queries entered at the San Jose site.a.Find all employees at the Boca plant.b.Find the average salary of all employees.c.Find the highest-paid employee at each of the following sites:Toronto,Edmonton,Vancouver,Montreal.d.Find the lowest-paid employee in the company.6Chapter19Distributed DatabasesAnswer:a.i.Send the query name(employee)to the Boca plant.ii.Have the Boca location send back the answer.pute average at New York.ii.Send answer to San Jose.c.i.Send the query tofind the highest salaried employee to Toronto,Edmonton,Vancouver,and Montreal.pute the queries at those sites.iii.Return answers to San Jose.d.i.Send the query tofind the lowest salaried employee to New York.pute the query at New York.iii.Send answer to San Jose.19.11Compute r⋉s for the relations of Figure19.9.Answer:The result is as follows.r⋉s=A B C12353219.12Give an example of an application ideally suited for the cloud and anotherthat would be hard to implement successfully in the cloud.Explain youranswer.Answer:Any application that is easy to partition,and does not needstrong guarantees of consistency across partitions,is ideally suited to thecloud.For example,Web-based document storage systems(like Googledocs),and Web based email systems(like Hotmail,Yahoo!mail or GMail),are ideally suited to the cloud.The cloud is also ideally suited to certainkinds of data analysis tasks where the data is already on the cloud;forexample,the Google Map-Reduce framework,and Yahoo!Hadoop arewidely used for data analysis of Web logs such as logs of URLs clicked byusers.Any database application that needs transactional consistency wouldbe hard to implement successfully in the cloud;examples include bankrecords,academic records of students,and many other types of organiza-tional records.19.13Given that the LDAP functionality can be implemented on top of a databasesystem,what is the need for the LDAP standard?Answer:The reasons are:a.Directory access protocols are simplified protocols that cater to alimited type of access to data.Practice Exercises7b.Directory systems provide a simple mechanism to name objects ina hierarchical fashion which can be used in a distributed directorysystem to specify what information is stored in each of the directoryservers.The directory system can be set up to automatically forwardqueries made at one site to the other site,without user intervention.19.14Consider a multidatabase system in which it is guaranteed that at mostone global transaction is active at any time,and every local site ensures local serializability.a.Suggest ways in which the multidatabase system can ensure thatthere is at most one active global transaction at any time.b.Show by example that it is possible for a nonserializable globalschedule to result despite the assumptions.Answer:a.We can have a special data item at some site on which a lock willhave to be obtained before starting a global transaction.The lockshould be released after the transaction completes.This ensures thesingle active global transaction requirement.To reduce dependencyon that particular site being up,we can generalize the solution byhaving an election scheme to choose one of the currently up sites tobe the co-ordinator,and requiring that the lock be requested on thedata item which resides on the currently elected co-ordinator.b.The following schedule involves two sites and four transactions.T1and T2are local transactions,running at site1and site2respectively.T G1and T G2are global transactions running at both sites.X1,Y1aredata items at site1,and X2,Y2are at site2.T1T2T G1T G2write(Y1)read(Y1)write(X2)read(X2)write(Y2)read(Y2)write(X1)read(X1)In this schedule,T G2starts only after T G1finishes.Within each site,there is local serializability.In site1,T G2→T1→T G1is a serializ-ability order.In site2,T G1→T2→T G2is a serializability order.Yetthe global schedule schedule is non-serializable.19.15Consider a multidatabase system in which every local site ensures localserializability,and all global transactions are read only.8Chapter19Distributed Databasesa.Show by example that nonserializable executions may result in sucha system.b.Show how you could use a ticket scheme to ensure global serializ-ability.Answer:a.The same system as in the answer to Exercise19.14is assumed,except that now both the global transactions are read-only.Considerthe schedule given below.Though there is local serializability in both sites,the global scheduleis not serializable.b.Since local serializability is guaranteed,any cycle in the system wideprecedence graph must involve at least two different sites,and twodifferent global transactions.The ticket scheme ensures that when-ever two global transactions access data at a site,they conflict ona data item(the ticket)at that site.The global transaction managercontrols ticket access in such a manner that the global transactionsexecute with the same serializability order in all the sites.Thus thechance of their participating in a cycle in the system wide precedencegraph is eliminated.。

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

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

第一部分基础理论第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.请简述关系规范化过程。

数据库系统原理教程课后习题答案

数据库系统原理教程课后习题答案

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

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

数据的种类有数字、文字、图形、图像、声音、正文等。

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

解析在现代计算机系统中数据的概念是广义的。

早期的计算机系统主要用于科学计算,处理的数据是整数、实数、浮点数等传统数学中的数据。

现代计算机能存储和处理的对象十分广泛,表示这些对象的数据也越来越复杂。

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

500 这个数字可以表示一件物品的价格是 500 元,也可以表示一个学术会议参加的人数有 500 人,还可以表示一袋奶粉重 500 克。

( 2 )数据库( DataBase ,简称 DB ) :数据库是长期储存在计算机内的、有组织的、可共享的数据集合。

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

( 3 )数据库系统( DataBas 。

Sytem ,简称 DBS ) :数据库系统是指在计算机系统中引入数据库后的系统构成,一般由数据库、数据库管理系统(及其开发工具)、应用系统、数据库管理员构成。

解析数据库系统和数据库是两个概念。

数据库系统是一个人一机系统,数据库是数据库系统的一个组成部分。

但是在日常工作中人们常常把数据库系统简称为数据库。

希望读者能够从人们讲话或文章的上下文中区分“数据库系统”和“数据库”,不要引起混淆。

( 4 )数据库管理系统( DataBase Management sytem ,简称 DBMs ) :数据库管理系统是位于用户与操作系统之间的一层数据管理软件,用于科学地组织和存储数据、高效地获取和维护数据。

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

解析 DBMS 是一个大型的复杂的软件系统,是计算机中的基础软件。

目前,专门研制 DBMS的厂商及其研制的 DBMS 产品很多。

数据库第六版第四章答案

数据库第六版第四章答案

Intermediate SQLPractice Exercises4.1Write the following queries in SQL:a.Display a list of all instructors,showing their ID,name,and the num-ber of sections that they have taught.Make sure to show the numberof sections as0for instructors who have not taught any section.Yourquery should use an outerjoin,and should not use scalar subqueries.b.Write the same query as above,but using a scalar subquery,withoutouterjoin.c.Display the list of all course sections offered in Spring2010,alongwith the names of the instructors teaching the section.If a section hasmore than one instructor,it should appear as many times in the resultas it has instructors.If it does not have any instructor,it should stillappear in the result with the instructor name set to“—”.d.Display the list of all departments,with the total number of instructorsin each department,without using scalar subqueries.Make sure tocorrectly handle departments with no instructors.Answer:a.Display a list of all instructors,showing their ID,name,and the num-ber of sections that they have taught.Make sure to show the numberof sections as0for instructors who have not taught any section.Yourquery should use an outerjoin,and should not use scalar subqueries.select ID,name,count(course id,section id,year,semester)as’Number of sections’from instructor natural left outer join teachesgroup by ID,nameThe above query should not be written using count(*)since count*counts null values also.It could be written using count(section id),or1920Chapter4Intermediate SQLany other attribute from teaches which does not occur in instructor,which would be correct although it may be confusing to the reader.(Attributes that occur in instructor would not be null even if the in-structor has not taught any section.)b.Write the same query as above,but using a scalar subquery,withoutouterjoin.select ID,name,(select count(*)as’Number of sections’from teaches T where T.id=I.id)from instructor Ic.Display the list of all course sections offered in Spring2010,alongwith the names of the instructors teaching the section.If a section hasmore than one instructor,it should appear as many times in the resultas it has instructors.If it does not have any instructor,it should stillappear in the result with the instructor name set to“−”.select course id,section id,ID,decode(name,NULL,’−’,name)from(section natural left outer join teaches)natural left outer join instructorwhere semester=’Spring’and year=2010The query may also be written using the coalesce operator,by re-placing decode(..)by coalesce(name,’−’).A more complex versionof the query can be written using union of join result with anotherquery that uses a subquery tofind courses that do not match;refer toexercise4.2.d.Display the list of all departments,with the total number of instructorsin each department,without using scalar subqueries.Make sure tocorrectly handle departments with no instructors.select dept name,count(ID)from department natural left outer join instructorgroup by dept name4.2Outer join expressions can be computed in SQL without using the SQLouter join operation.To illustrate this fact,show how to rewrite each of thefollowing SQL queries without using the outer join expression.a.select*from student natural left outer join takesb.select*from student natural full outer join takesAnswer:a.select*from student natural left outer join takescan be rewritten as:Exercises21 select*from student natural join takesunionselect ID,name,dept name,tot cred,NULL,NULL,NULL,NULL,NULLfrom student S1where not exists(select ID from takes T1where T1.id=S1.id)b.select*from student natural full outer join takescan be rewritten as:(select*from student natural join takes)union(select ID,name,dept name,tot cred,NULL,NULL,NULL,NULL,NULLfrom student S1where not exists(select ID from takes T1where T1.id=S1.id))union(select ID,NULL,NULL,NULL,course id,section id,semester,year,gradefrom takes T1where not exists(select ID from student S1where T1.id=S1.id))4.3Suppose we have three relations r(A,B),s(B,C),and t(B,D),with allattributes declared as not null.Consider the expressions•r natural left outer join(s natural left outer join t),and•(r natural left outer join s)natural left outer join ta.Give instances of relations r,s and t such that in the result of thesecond expression,attribute C has a null value but attribute D has anon-null value.b.Is the above pattern,with C null and D not null possible in the resultof thefirst expression?Explain why or why not.Answer:a.Consider r=(a,b),s=(b1,c1),t=(b,d).The second expression wouldgive(a,b,NULL,d).b.It is not possible for D to be not null while C is null in the result of thefirst expression,since in the subexpression s natural left outer join t,it is not possible for C to be null while D is not null.In the overallexpression C can be null if and only if some r tuple does not have amatching B value in s.However in this case D will also be null.4.4Testing SQL queries:To test if a query specified in English has been cor-rectly written in SQL,the SQL query is typically executed on multiple test22Chapter4Intermediate SQLdatabases,and a human checks if the SQL query result on each test databasematches the intention of the specification in English.a.In Section Section3.3.3The Natural Joinsubsection.3.3.3we saw an ex-ample of an erroneous SQL query which was intended tofind whichcourses had been taught by each instructor;the query computed thenatural join of instructor,teaches,and course,and as a result uninten-tionally equated the dept name attribute of instructor and course.Givean example of a dataset that would help catch this particular error.b.When creating test databases,it is important to create tuples in refer-enced relations that do not have any matching tuple in the referencingrelation,for each foreign key.Explain why,using an example queryon the university database.c.When creating test databases,it is important to create tuples with nullvalues for foreign key attributes,provided the attribute is nullable(SQL allows foreign key attributes to take on null values,as long asthey are not part of the primary key,and have not been declared asnot null).Explain why,using an example query on the universitydatabase.Hint:use the queries from Exercise Exercise4.1Item.138.Answer:a.Consider the case where a professor in Physics department teaches anElec.Eng.course.Even though there is a valid corresponding entryin teaches,it is lost in the natural join of instructor,teaches and course,since the instructors department name does not match the departmentname of the course.A dataset corresponding to the same is:instructor={(12345,’Guass’,’Physics’,10000)}teaches={(12345,’EE321’,1,’Spring’,2009)}course={(’EE321’,’Magnetism’,’Elec.Eng.’,6)}b.The query in question0.a is a good example for this.Instructors whohave not taught a single course,should have number of sections as0in the query result.(Many other similar examples are possible.)c.Consider the queryselect*from teaches natural join instructor;In the above query,we would lose some sections if teaches.ID is al-lowed to be NULL and such tuples exist.If,just because teaches.ID isa foreign key to instructor,we did not create such a tuple,the error inthe above query would not be detected.4.5Show how to define the view student grades(ID,GP A)giving the grade-point average of each student,based on the query in Exercise??;recallthat we used a relation grade points(grade,points)to get the numeric pointsExercises23 associated with a letter grade.Make sure your view definition correctly handles the case of null values for the grade attribute of the takes relation.Answer:We should not add credits for courses with a null grade;further to to correctly handle the case where a student has not completed any course, we should make sure we don’t divide by zero,and should instead return a null value.We break the query into a subquery thatfinds sum of credits and sum of credit-grade-points,taking null grades into account The outer query divides the above to get the average,taking care of divide by0.create view student grades(ID,GP A)asselect ID,credit points/decode(credit sum,0,NULL,credit sum)from((select ID,sum(decode(grade,NULL,0,credits))as credit sum,sum(decode(grade,NULL,0,credits*points))as credit pointsfrom(takes natural join course)natural left outer join grade pointsgroup by ID)unionselect ID,NULLfrom studentwhere ID not in(select ID from takes))The view defined above takes care of NULL grades by considering the creditpoints to be0,and not adding the corresponding credits in credit sum.The query above ensures that if the student has not taken any course with non-NULL credits,and has credit sum=0gets a gpa of NULL.This avoid the division by0,which would otherwise have resulted.An alternative way of writing the above query would be to use student natural left outer join gpa,in order to consider students who have not taken any course.4.6Complete the SQL DDL definition of the university database of Figure Fig-ure4.8Referential Integrityfigcnt.50to include the relations student,takes, advisor,and prereq.Answer:create table student(ID varchar(5),name varchar(20)not null,dept name varchar(20),tot cred numeric(3,0)check(tot cred>=0),primary key(ID),foreign key(dept name)references departmenton delete set null);24Chapter4Intermediate SQLcreate table takes(ID varchar(5),course id varchar(8),section id varchar(8),semester varchar(6),year numeric(4,0),grade varchar(2),primary key(ID,course id,section id,semester,year),foreign key(course id,section id,semester,year)references sectionon delete cascade,foreign key(ID)references studenton delete cascade);create table advisor(i id varchar(5),s id varchar(5),primary key(s ID),foreign key(i ID)references instructor(ID)on delete set null,foreign key(s ID)references student(ID)on delete cascade);create table prereq(course id varchar(8),prereq id varchar(8),primary key(course id,prereq id),foreign key(course id)references courseon delete cascade,foreign key(prereq id)references course);4.7Consider the relational database of Figure Figure4.11figcnt.53.Give an SQLDDL definition of this database.Identify referential-integrity constraintsthat should hold,and include them in the DDL definition.Answer:create table employee(person name char(20),street char(30),city char(30),primary key(person name))Exercises25create table works(person name char(20),company name char(15),salary integer,primary key(person name),foreign key(person name)references employee,foreign key(company name)references company)create table company(company name char(15),city char(30),primary key(company name))pp create table manages(person name char(20),manager name char(20),primary key(person name),foreign key(person name)references employee,foreign key(manager name)references employee)Note that alternative datatypes are possible.Other choices for not nullattributes may be acceptable.4.8As discussed in Section Section4.4.7Complex Check Conditions and Assertionssubsection.4.4we expect the constraint“an instructor cannot teach sections in two differ-ent classrooms in a semester in the same time slot”to hold.a.Write an SQL query that returns all(instructor,section)combinationsthat violate this constraint.b.Write an SQL assertion to enforce this constraint(as discussed in Sec-tion Section4.4.7Complex Check Conditions and Assertionssubsection.4.4.7,current generation database systems do not support such assertions,although they are part of the SQL standard).Answer:a.select ID,name,section id,semester,year,time slot id,count(distinct building,room number)from instructor natural join teaches natural join sectiongroup by(ID,name,section id,semester,year,time slot id)having count(building,room number)>1Note that the distinct keyword is required above.This is to allow twodifferent sections to run concurrently in the same time slot and are26Chapter4Intermediate SQLtaught by the same instructor,without being reported as a constraintviolation.b.create assertion check not exists(select ID,name,section id,semester,year,time slot id,count(distinct building,room number)from instructor natural join teaches natural join sectiongroup by(ID,name,section id,semester,year,time slot id)having count(building,room number)>1)4.9SQL allows a foreign-key dependency to refer to the same relation,as in thefollowing example:create table manager(employee name char(20),manager name char(20),primary key employee name,foreign key(manager name)references manageron delete cascade)Here,employee name is a key to the table manager,meaning that each em-ployee has at most one manager.The foreign-key clause requires that everymanager also be an employee.Explain exactly what happens when a tuplein the relation manager is deleted.Answer:The tuples of all employees of the manager,at all levels,getdeleted as well!This happens in a series of steps.The initial deletion willtrigger deletion of all the tuples corresponding to direct employees ofthe manager.These deletions will in turn cause deletions of second levelemployee tuples,and so on,till all direct and indirect employee tuples aredeleted.4.10SQL-92provides an n-ary operation called coalesce,which is defined asfollows:coalesce(A1,A2,...,A n)returns thefirst nonnull A i in the listA1,A2,...,A n,and returns null if all of A1,A2,...,A n are null.Let a and b be relations with the schemas A(name,address,title)and B(name,address,salary),respectively.Show how to express a natural full outer joinb using the full outer-join operation with an on condition and the coalesceoperation.Make sure that the result relation does not contain two copiesof the attributes name and address,and that the solution is correct even ifsome tuples in a and b have null values for attributes name or address.Answer:Exercises27 select coalesce(,)as name,coalesce(a.address,b.address)as address,a.title,b.salaryfrom a full outer join b on = anda.address=b.address4.11Some researchers have proposed the concept of marked nulls.A markednull⊥i is equal to itself,but if i=j,then⊥i=⊥j.One application of marked nulls is to allow certain updates through views.Consider the view instructor info(Section Section4.2Viewssection.4.2).Show how you can use marked nulls to allow the insertion of the tuple(99999,“Johnson”,“Music”) through instructor info.Answer:To insert the tuple(99999,“(”Johnson),“Music”)into the view instructor info,we can do the following:instructor←(99999,“Johnson”,⊥k,⊥)∪instructordepartment←(⊥k,“Music′′,⊥)∪departmentsuch that⊥k is a new marked null not already existing in the database.Note:“Music”here is the name of a building and may or may not be related to Music department.。

数据库系统概念(database system concepts)英文第六版 课后练习题 答案 第26章

数据库系统概念(database system concepts)英文第六版 课后练习题 答案 第26章
Chapter 26: Advanced Transam Concepts, 6th Ed.
©Silberschatz, Korth and Sudarshan See for conditions on re-use
With the growth of networks, and the existence of multiple autonomous
database systems, workflows provide a convenient way of carrying out tasks that involve multiple systems.
Provide infrastructure for building and administering complex transaction
processing systems with a large number of clients and multiple servers.
Provide services such as:
Some commercial TP monitors: CICS from IBM, Pathway from Tandem,
Top End from NCR, and Encina from Transarc
Database System Concepts - 6th Edition
26.3
©Silberschatz, Korth and Sudarshan
TP Monitor Architectures
Database System Concepts - 6th Edition
26.4
©Silberschatz, Korth and Sudarshan

数据库课后习题答案(全)

数据库课后习题答案(全)

第1章数据库系统概述习题参考答案1.1 数据处理和数据库应用的例子:电话公司使用数据库存储客户基本信息、客户的每次通话信息以及雇员基本信息、雇员业绩信息等。

典型的数据处理包括电话收费、生成客户长途电话话单、计算雇员工资等图书馆使用数据库存储图书资料信息、读者基本信息、图书借阅信息等。

典型的数据处理包括新书登记、处理读者借还图书等税务局使用数据库存储纳税人(个人或公司)信息、纳税人缴纳税款信息等。

典型的数据处理包括纳税、退税处理、统计各类纳税人纳税情况等。

银行使用数据库存储客户基本信息、客户存贷款信息等。

典型的数据处理包括处理客户存取款等。

超市使用数据库存储商品的基本信息、会员客户基本信息、客户每次购物的详细清单。

典型的数据处理包括收银台记录客户每次购物的清单并计算应交货款。

1.2 DBMS是数据库管理系统的简称,是一种重要的程序设计系统。

它由一个相互关联的数据集合和一组访问这些数据的程序组成。

数据库是持久储存在计算机中、有组织的、可共享的大量数据的集合。

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

数据库系统由数据库、DBMS(及其开发工具)、应用系统和数据库管理员组成。

数据模型是一种形式机制,用于数据建模,描述数据、数据之间的联系、数据的语义、数据上的操作和数据的完整性约束条件。

数据库模式是数据库中使用数据模型对数据建模所产生设计结果。

对于关系数据库而言,数据库模式由一组关系模式构成。

数据字典是DBMS维护的一系列内部表,用来存放元数据。

所谓元数据是关于数据的数据。

1.3 DBMS提供如下功能:(1)数据定义:提供数据定义语言DDL,用于定义数据库中的数据对象和它们的结构。

(2)数据操纵:提供数据操纵语言DML,用于操纵数据,实现对数据库的基本操作(查询、插入、删除和修改)。

(3)事务管理和运行管理:统一管理数据、控制对数据的并发访问,保证数据的安全性、完整性,确保故障时数据库中数据不被破坏,并且能够恢复到一致状态。

数据库系统概念(database system concepts)英文第六版 课后练习题 答案 第11章

数据库系统概念(database system concepts)英文第六版 课后练习题 答案 第11章

2Chapter11Indexing and Hashingb.c.11.4Answer:•With structure11.3.a:Insert9:10:InsertExercises3Delete23:Delete19:•With structure11.3.b:Insert9:Insert4Chapter 11Indexing and HashingDelete23:Delete 19:•With structure 11.3.c:Insert9:Insert10:Insert8:Delete 23:Delete 19:Exercises511.5Answer:If there are K search-key values and m −1siblings are involvedin the redistribution,the expected height of the tree is:log ⌊(m −1)n /m ⌋(K )11.6Answer:Extendable hash structure000 001010 011 100101 110 11111.7Answer:a.Delete 11:From the answer to Exercise 11.6,change the third bucketto:At this stage,it is possible to coalesce the second and third buckets.Then it is enough if the bucket address table has just four entriesinstead of eight.For the purpose of this answer,we do not do the coalescing.b.Delete 31:From the answer to 11.6,change the last bucket to:6Chapter11Indexing and Hashingc.Insert1:From the answer to11.6,change thefirst bucket to:d.Insert15:From the answer to11.6,change the last bucket to:11.8Answer:The pseudocode is shown in Figure11.1.11.9Answer:Let i denote the number of bits of the hash value used in thehash table.Let bsize denote the maximum capacity of each bucket.Thepseudocode is shown in Figure11.2.Note that we can only merge two buckets at a time.The common hashprefix of the resultant bucket will have length one less than the two bucketsmerged.Hence we look at the buddy bucket of bucket j differing from itonly at the last bit.If the common hash prefix of this bucket is not i j,thenthis implies that the buddy bucket has been further split and merge is notpossible.When merge is successful,further merging may be possible,which is handled by a recursive call to coalesce at the end of the function.11.10Answer:If the hash table is currently using i bits of the hash value,thenmaintain a count of buckets for which the length of common hash prefixis exactly i.Consider a bucket j with length of common hash prefix i j.If the bucketis being split,and i j is equal to i,then reset the count to1.If the bucketis being split and i j is one less that i,then increase the count by1.It thebucket if being coalesced,and i j is equal to i then decrease the count by1.If the count becomes0,then the bucket address table can be reduced insize at that point.However,note that if the bucket address table is not reduced at that point,then the count has no significance afterwards.If we want to postpone thereduction,we have to keep an array of counts,i.e.a count for each value ofExercises7 functionfindIterator(value V){/*Returns an iterator for the search on the value V*/Iterator iter();Set iter.v alue=V;Set C=root nodewhile(C is not a leaf node)beginLet i=samllest number such that V<=C.K iif there is no such number i then beginLet P m=last non-null pointer in the nodeSet C=C.P m;endelse Set C=C.P i;end/*C is a leaf node*/Let i be the least value such that K i=Vif there is such a value i then beginSet iter.index=i;Set iter.page=C;Set iter.acti v e=T RUE;endelse if(V is the greater than the largest value in the leaf)then beginif(C.P n.K1=V)then beginSet iter.page=C.P n;Set iter.index=1;Set iter.acti v e=T RUE;endelse Set iter.acti v e=F AL SE;endelse Set iter.acti v e=F AL SE;return(iter)}Class Iterator{variables:value V/*The value on which the index is searched*/boolean active/*Stores the current state of the iterator(TRUE or FALSE)*/int index/*Index of the next matching entry(if active is TRUE)*/PageID page/*Page Number of the next matching entry(if active is TRUE)*/ function next(){if(active)then beginSet ret Page=page;Set retI ndex=index;if(index+1=page.size)then beginpage=page.P nindex=0endelse index=index+1;if(page.K index=V)then acti v e=F AL SE;return(ret Page,retI ndex)endelse return null;}}Figure11.1Pseudocode forfindIterator and the Iterator class8Chapter11Indexing and Hashingdelete(value K l)beginj=first i high-order bits of h(K l);delete value K l from bucket j;coalesce(bucket j);endcoalesce(bucket j)begini j=bits used in bucket j;k=any bucket withfirst(i j−1)bits same as thatof bucket j while the bit i j is reversed;i k=bits used in bucket k;if(i j=i k)return;/*buckets cannot be merged*/if(entries in j+entries in k>bsize)return;/*buckets cannot be merged*/move entries of bucket k into bucket j;decrease the value of i j by1;make all the bucket-address-table entries,which pointed to bucket k,point to j;coalesce(bucket j);endFigure11.2Pseudocode for deletioncommon hash prefix.The array has to be updated in a similar fashion.Thebucket address table can be reduced if the i th entry of the array is0,wherei is the number of bits the table is using.Since bucket table reduction isan expensive operation,it is not always advisable to reduce the table.Itshould be reduced only when sufficient number of entries at the end ofcount array become0.11.11Answer:We reproduce the instructor relation below.Exercises9 ID dept salary10101Comp.Sci.Wu9000015151MusicEinstein9500032343HistoryGold8700045565Comp.Sci.Califieri6200076543FinanceCrick7200083821Comp.Sci.Kim80000a.Bitmap for salary,with S1,S2,S3and S4representing the given inter-vals in the same orderS1000000000000S3010*********b.The question is a bit trivial if there is no bitmap on the deptname attribute is:Comp.Sci010********* Music000101000000 History000000000100 Elec.Eng.010********* Finance010*********10Chapter11Indexing and HashingScan on these records with salary80000or more gives Wu and Singhas the instructors who satisfy the given query.11.12Answer:If the index entries are inserted in ascending order,the newentries get directed to the last leaf node.When this leaf node getsfilled,it is split into two.Of the two nodes generated by the split,the left nodeis left untouched and the insertions takes place on the right node.Thismakes the occupancy of the leaf nodes to about50percent,except the lastleaf.If keys that are inserted are sorted in descending order,the above situationwould still occur,but symmetrically,with the right node of a split nevergetting touched again,and occupancy would again be50percent for allnodes other than thefirst leaf.11.13Answer:a.The cost to locate the page number of the required leaf page foran insertion is negligible since the non-leaf nodes are in memory.On the leaf level it takes one random disk access to read and onerandom disk access to update it along with the cost to write onepage.Insertions which lead to splitting of leaf nodes require anadditional page write.Hence to build a B+-tree with n r entries ittakes a maximum of2∗n r random disk accesses and n r+2∗(n r/f)page writes.The second part of the cost comes from the fact that inthe worst case each leaf is halffilled,so the number of splits thatoccur is twice n r/f.The above formula ignores the cost of writing non-leaf nodes,sincewe assume they are in memory,but in reality they would also bewritten eventually.This cost is closely approximated by2∗(n r/f)/f,which is the number of internal nodes just above the leaf;we canadd further terms to account for higher levels of nodes,but these aremuch smaller than the number of leaves and can be ignored.b.Substituting the values in the above formula and neglecting the costfor page writes,it takes about10,000,000∗20milliseconds,or56hours,since each insertion costs20milliseconds.Exercises11c.function insert leaf(value K,pointer P)if(tree is empty)create an empty leaf node L,which is also the rootelse Find the last leaf node in the leaf nodes chain Lif(L has less than n−1key values)then insert(K,P)at thefirst available location in Lelse beginCreate leaf node L1Set L.P n=L1;Set K1=last value from page Linsert parent(1,L,K1,L1)insert(K,P)at thefirst location in L1endfunction insert parent(level l,pointer P,value K,pointer P1)if(level l is empty)then beginCreate an empty non-leaf node N,which is also the rootinsert(P,K,P1)at the starting of the node Nreturnelse beginFind the right most node N at level lif(N has less than n pointers)then insert(K,P1)at thefirst available location in Nelse beginCreate a new non-leaf page N1insert(P1)at the starting of the node Ninsert parent(l+1,pointer N,value K,pointer N1)endendThe insert leaf function is called for each of the value,pointerpairs in ascending order.Similar function can also be build for de-scending order.The search for the last leaf or non-leaf node at anylevel can be avoided by storing the current last page details in anarray.The last node in each level might be less than halffilled.To makethis index structure meet the requirements of a B+-tree,we can re-distribute the keys of the last two pages at each level.Since the lastbut one node is always full,redistribution makes sure that both ofthen are at least halffilled.11.14Answer:In a B+-tree index orfile organization,leaf nodes that areadjacent to each other in the tree may be located at different places ondisk.When afile organization is newly created on a set of records,it ispossible to allocate blocks that are mostly contiguous on disk to leafsnodes that are contiguous in the tree.As insertions and deletions occur12Chapter11Indexing and Hashingon the tree,sequentiality is increasingly lost,and sequential access has towait for disk seeks increasingly often.a.One way to solve this problem is to rebuild the index to restoresequentiality.b.i.In the worst case each n-block unit and each node of the B+-treeis halffilled.This gives the worst case occupancy as25percent.ii.No.While splitting the n-block unit thefirst n/2leaf pages areplaced in one n-block unit,and the remaining in the second n-block unit.That is,every n-block split maintains the order.Hence,the nodes in the n-block units are consecutive.iii.In the regular B+-tree construction,the leaf pages might not besequential and hence in the worst case,it takes one seek per leafing the block at a time method,for each n-node block,we will have at least n/2leaf nodes in it.Each n-node block canbe read using one seek.Hence the worst case seeks comes downby a factor of n/2.iv.Allowing redistribution among the nodes of the same block,doesnot require additional seeks,where as,in regular B+-tree werequire as many seeks as the number of leaf pages involvedin the redistribution.This makes redistribution for leaf blocksefficient with this scheme.Also the worst case occupancy comesback to nearly50percent.(Splitting of leaf nodes is preferredwhen the participating leaf nodes are nearly full.Hence nearly50percent instead of exact50percent)。

数据库系统概论第六版课后答案

数据库系统概论第六版课后答案

数据库系统概论第六版课后答案第1章数据库系统概述一、填空题1. 在关系数据库中,一个元组对应表中。

解: 一个记录 (一行)2. 常用的数据模型有:、、和面向对象模型。

解: 关系模型,层次模型,网状模型3. 用二维表来表示实体及实体之间联系的数据模型是。

解: 关系模型4. 关系模型数据库中最常用的三种关系运算是、、。

解: 选择运算,投影运算,连接运算5. 在数据库系统中,数据的最小访问单位是。

解: 字段(数据项)6. 对表进行水平方向的分割用的运算是。

解: 选择运算7. 数据结构、和称为数据模型的三要素。

解: 数据操作,数据约束条件8. 关系的完整性约束条件包括完整性、完整性和完整性三种。

解: 用户定义,实体,参照二、单项选择题1. 对数据库进行规划、设计、协调、维护和管理的人员,通常被称为(D )。

A. 工程师B. 用户C. 程序员D. 数据库管理员2. 下面关于数据(Data)、数据库(DB)、数据库管理系统(DBMS)与数据库系统(DBS)之间关系的描述正确的是( B )。

A. DB包含DBMS和DBSB. DBMS包含DB和DBSC. DBS包含DB和DBMSD. 以上都不对3. 数据库系统的特点包括( D )。

A. 实现数据共享,减少数据冗余B. 具有较高的数据独立性、具有统一的数据控制功能C. 采用特定的数据模型D. 以上特点都包括4. 下列各项中,对数据库特征的描述不准确的是( D )。

A. 数据具有独立性B. 数据结构化C. 数据集中控制D. 没有冗余5. 在数据的组织模型中,用树形结构来表示实体之间联系的模型称为 ( D )。

A. 关系模型B. 层次模型C. 网状模型D. 数据模型6. 在数据库中,数据模型描述的是 ( C ) 的集合。

A. 文件B. 数据C. 记录D. 记录及其联系7. 在关系数据库中,关系就是一个由行和列构成的二维表,其中行对应( B )。

A. 属性B. 记录C. 关系D. 主键8. 关系数据库管理系统所管理的关系是( C )。

数据库英文版第六版课后答案

数据库英文版第六版课后答案

数据库英文版第六版课后答案Chapter 1: IntroductionQuestions1.What is a database?A database is a collection of organized and structured data stored electronically in a computer system. It allows users to efficiently store, retrieve, and manipulate large amounts of data.2.What are the advantages of using a database system?–Data sharing and integration: A database system allows multiple users to access and share data simultaneously.–Data consistency and integrity: A database system enforces rules and constraints to maintain the accuracy and integrity of the data.–Data security: A database system provides access control mechanisms to ensure that data is accessed by authorized users only.–Data independence: A database system separates the data from the application programs that use it, allowing for easier applicationdevelopment and maintenance.Exercises1.Discuss the advantages and disadvantages of using a database system.Advantages:–Data sharing and integration–Data consistency and integrity–Data security–Data independenceDisadvantages:–Cost: Database systems can be expensive to set up and maintain.–Complexity: Database systems require a certain level of expertise to design, implement, and manage.–Performance overhead: Database systems may introduce some overhead in terms of storage and processing.Overall, the advantages of using a database system outweigh the disadvantages in most cases, especially for large-scale applications with multiple users and complex data requirements.Chapter 2: Relational Model and Relational Algebra Questions1.What is a relation? How is it represented in the relational model?A relation is a table-like structure that represents a set of related data. It is represented as a two-dimensional table with rows and columns, where each row corresponds to a record and each column corresponds to a attribute or field.2.What is the primary key of a relation?The primary key of a relation is a unique identifier for each record in the relation. It is used to ensure the uniqueness and integrity of the data.Exercises1.Consider the following relation:Employees (EmpID, Name, Age, Salary)–EmpID is the primary key of the Employees relation.–Name, Age, and Salary are attributes of the Employees relation.2.Write a relational algebra expression to retrieve the names of all employees whose age is greater than 30.π Name (σ Age > 30 (Employees))Chapter 3: SQLQuestions1.What is SQL?SQL (Structured Query Language) is a programming language designed for managing and manipulating relational databases. It provides a set of commands and statements that allow users to create, modify, and query databases.2.What are the main components of an SQL statement?An SQL statement consists of the following main components:–Keywords: SQL commands and instructions.–Clauses: Criteria and conditions that specify what data to retrieve or modify.–Expressions: Values, variables, or calculations used in SQL statements.–Operators: Symbols used to perform operations on data. Exercises1.Write an SQL statement to create a table called。

数据库系统概念(database system concepts)英文第六版 课后练习题 答案 第17章

数据库系统概念(database system concepts)英文第六版 课后练习题 答案 第17章

C H A P T E R17Database System ArchitecturesPractice Exercises17.1Instead of storing shared structures in shared memory,an alternativearchitecture would be to store them in the local memory of a specialprocess,and access the shared data by interprocess communicationwith the process.What would be the drawback of such an architecture?Answer:The drawbacks would be that two interprocess messageswould be required to acquire locks,one for the request and one toconfirm grant.Interprocess communication is much more expensivethan memory access,so the cost of locking would increase.The processstoring the shared structures could also become a bottleneck.The benefit of this alternative is that the lock table is protected betterfrom erroneous updates since only one process can access it.17.2In typical client–server systems the server machine is much more pow-erful than the clients;that is,its processor is faster,it may have multipleprocessors,and it has more memory and disk capacity.Consider in-stead a scenario where client and server machines have exactly thesame power.Would it make sense to build a client–server system insuch a scenario?Why?Which scenario would be better suited to adata-server architecture?Answer:With powerful clients,it still makes sense to have a client-server system,rather than a fully centralized system.If the data-serverarchitecture is used,the powerful clients can off-load all the long andcompute intensive transaction processing work from the server,freeingit to perform only the work of satisfying read-write requests.even ifthe transaction-server model is used,the clients still take care of theuser-interface work,which is typically very compute-intensive.A fully distributed system might seem attractive in the presence ofpowerful clients,but client-server systems still have the advantage ofsimpler concurrency control and recovery schemes to be implemented1718Chapter17Database System Architectureson the server alone,instead of having these actions distributed in allthe machines.17.3Consider a database system based on a client–server architecture,withthe server acting as a data server.a.What is the effect of the speed of the interconnection betweenthe client and the server on the choice between tuple and pageshipping?b.If page shipping is used,the cache of data at the client can beorganized either as a tuple cache or a page cache.The page cachestores data in units of a page,while the tuple cache stores data inunits of tuples.Assume tuples are smaller than pages.Describeone benefit of a tuple cache over a page cache.Answer:a.We assume that tuples are smaller than a page andfit in a page.If the interconnection link is slow it is better to choose tuple ship-ping,as in page shipping a lot of time will be wasted in shippingtuples that might never be needed.With a fast interconnectionthough,the communication overheads and latencies,not the ac-tual volume of data to be shipped,becomes the bottle neck.Inthis scenario page shipping would be preferable.b.Two benefits of an having a tuple-cache rather than a page-cache,even if page shipping is used,are:i.When a client runs out of cache space,it can replace objectswithout replacing entire pages.The reduced caching granu-larity might result in better cache-hit ratios.ii.It is possible for the server to ask clients to return some ofthe locks which they hold,but don’t need(lock de-escalation).Thus there is scope for greater concurrency.If page caching isused,this is not possible.17.4Suppose a transaction is written in C with embedded SQL,and about80percent of the time is spent in the SQL code,with the remaining20percent spent in C code.How much speedup can one hope to attain ifparallelism is used only for the SQL code?Explain.Answer:Since the part which cannot be parallelized takes20%of thetotal running time,the best speedup we can hope for has to be less than5.17.5Some database operations such as joins can see a significant differencein speed when data(for example,one of the relations involved in ajoin)fits in memory as compared to the situation where the data doesnotfit in memory.Show how this fact can explain the phenomenonof superlinear speedup,where an application sees a speedup greaterthan the amount of resources allocated to it.Answer:FILLPractice Exercises19 17.6Parallel systems often have a network structure where sets of n pro-cessors connect to a single Ethernet switch,and the Ethernet switches themselves connect to another Ethernet switch.Does this architecture correspond to a bus,mesh or hypercube architecture?If not,how would you describe this interconnection architecture?Answer:FILL。

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

C H A P T E R2Introduction to the Relational ModelPractice Exercises2.1Consider the relational database of Figure??.What are the appropriateprimary keys?Answer:The answer is shown in Figure2.1,with primary keys under-lined.2.2Consider the foreign key constraint from the dept name attribute of in-structor to the department relation.Give examples of inserts and deletes tothese relations,which can cause a violation of the foreign key constraint.Answer:•Inserting a tuple:(10111,Ostrom,Economics,110,000)into the instructor table,where the department table does not have thedepartment Economics,would violate the foreign key constraint.•Deleting the tuple:(Biology,Watson,90000)from the department table,where at least one student or instructortuple has dept name as Biology,would violate the foreign key con-straint.employee(person name,street,city)works(person name company name,salary)company(company name,city)Figure2.1Relational database for Practice Exercise2.1.12Chapter2Introduction to the Relational Model2.3Consider the time slot relation.Given that a particular time slot can meetmore than once in a week,explain why day and start time are part of theprimary key of this relation,while end time is not.Answer:The attributes day and start time are part of the primary keysince a particular class will most likely meet on several different days,and may even meet more than once in a day.However,end time is notpart of the primary key since a particular class that starts at a particulartime on a particular day cannot end at more than one time.2.4In the instance of instructor shown in Figure??,no two instructors havethe same name.From this,can we conclude that name can be used as asuperkey(or primary key)of instructor?Answer:No.For this possible instance of the instructor table the namesare unique,but in general this may not be always the case(unless theuniversity has a rule that two instructors cannot have the same name,which is a rather unlikey scenario).2.5What is the result offirst performing the cross product of student andadvisor,and then performing a selection operation on the result with thepredicate s id=ID?(Using the symbolic notation of relational algebra,this query can be written as␴s id=I D(student×advisor).)Answer:The result attributes include all attribute values of studentfollowed by all attributes of advisor.The tuples in the result are asfollows.For each student who has an advisor,the result has a rowcontaining that students attributes,followed by an s id attribute identicalto the students ID attribute,followed by the i id attribute containing theID of the students advisor.Students who do not have an advisor will not appear in the result.Astudent who has more than one advisor will appear a correspondingnumber of times in the result.2.6Consider the following expressions,which use the result of a relationalalgebra operation as the input to another operation.For each expression,explain in words what the expression does.a.␴year≥2009(takes)1studentb.␴year≥2009(takes1student)c. ID,name,course id(student1takes)Answer:a.For each student who takes at least one course in2009,displaythe students information along with the information about whatcourses the student took.The attributes in the result are:ID,name,dept name,tot cred,course id,section id,semester,year,gradeb.Same as(a);selection can be done before the join operation.c.Provide a list of consisting ofExercises3ID,name,course idof all students who took any course in the university.2.7Consider the relational database of Figure??.Give an expression in therelational algebra to express each of the following queries:a.Find the names of all employees who live in city“Miami”.b.Find the names of all employees whose salary is greater than$100,000.c.Find the names of all employees who live in“Miami”and whosesalary is greater than$100,000.Answer:a. name(␴city=“Miami”(employee))b. name(␴salary>100000(employee))c. name(␴city=“Miami”∧salary>100000(employee))2.8Consider the bank database of Figure??.Give an expression in therelational algebra for each of the following queries.a.Find the names of all branches located in“Chicago”.b.Find the names of all borrowers who have a loan in branch“Down-town”.Answer:a. branch name(␴branch city=“Chicago”(branch))b. customer name(␴branch name=“Downtown”(borro w er1loan))。

相关文档
最新文档