数据库系统基础教程第二章答案(共19页).doc

上传人:飞****2 文档编号:13328881 上传时间:2022-04-28 格式:DOC 页数:19 大小:1.20MB
返回 下载 相关 举报
数据库系统基础教程第二章答案(共19页).doc_第1页
第1页 / 共19页
数据库系统基础教程第二章答案(共19页).doc_第2页
第2页 / 共19页
点击查看更多>>
资源描述

《数据库系统基础教程第二章答案(共19页).doc》由会员分享,可在线阅读,更多相关《数据库系统基础教程第二章答案(共19页).doc(19页珍藏版)》请在taowenge.com淘文阁网|工程机械CAD图纸|机械工程制图|CAD装配图下载|SolidWorks_CaTia_CAD_UG_PROE_设计图分享下载上搜索。

1、精选优质文档-倾情为你奉上Exercise 2.2.1aFor relation Accounts, the attributes are:acctNo, type, balanceFor relation Customers, the attributes are:firstName, lastName, idNo, accountExercise 2.2.1bFor relation Accounts, the tuples are:(12345, savings, 12000),(23456, checking, 1000),(34567, savings, 25)For relatio

2、n Customers, the tuples are:(Robbie, Banks, 901-222, 12345),(Lena, Hand, 805-333, 12345),(Lena, Hand, 805-333, 23456)Exercise 2.2.1cFor relation Accounts and the first tuple, the components are: acctNosavings type12000 balanceFor relation Customers and the first tuple, the components are:Robbie firs

3、tNameBanks lastName901-222 idNo12345 accountExercise 2.2.1dFor relation Accounts, a relation schema is:Accounts(acctNo, type, balance)For relation Customers, a relation schema is:Customers(firstName, lastName, idNo, account)Exercise 2.2.1eAn example database schema is:Accounts (acctNo,type,balance)C

4、ustomers (firstName,lastName,idNo,account)Exercise 2.2.1fA suitable domain for each attribute:acctNo Integertype Stringbalance IntegerfirstName StringlastName StringidNo String (because there is a hyphen we cannot use Integer)account IntegerExercise 2.2.1gAnother equivalent way to present the Accoun

5、t relation:acctNobalancetype3456725savings234561000checking1234512000savingsAnother equivalent way to present the Customers relation:idNofirstNamelastNameaccount805-333LenaHand23456805-333LenaHand12345901-222RobbieBanks12345Exercise 2.2.2Examples of attributes that are created for primarily serving

6、as keys in a relation:Universal Product Code (UPC) used widely in United States and Canada to track products in stores.Serial Numbers on a wide variety of products to allow the manufacturer to individually track each product.Vehicle Identification Numbers (VIN), a unique serial number used by the au

7、tomotive industry to identify vehicles.Exercise 2.2.3aWe 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.Exercise 2.2.3bWe can order the three tuples in any of 5! = 120 ways. Also, the columns can

8、 be ordered in any of 4! = 24 ways. Thus, the number of presentations is 120*24 = 2880Exercise 2.2.3cWe can order the three tuples in any of m! ways. Also, the columns can be ordered in any of n! ways. Thus, the number of presentations is n!m!Exercise 2.3.1aCREATE TABLE Product (makerCHAR(30),modelC

9、HAR(10) PRIMARY KEY,type CHAR(15);Exercise 2.3.1bCREATE TABLE PC (model CHAR(30),speed DECIMAL(4,2),ram INTEGER,hd INTEGER,price DECIMAL(7,2);Exercise 2.3.1cCREATE TABLE Laptop (model CHAR(30),speed DECIMAL(4,2),ram INTEGER,hd INTEGER,screen DECIMAL(3,1),price DECIMAL(7,2);Exercise 2.3.1dCREATE TABL

10、E Printer (model CHAR(30),color BOOLEAN,type CHAR (10),price DECIMAL(7,2);Exercise 2.3.1eALTER TABLE Printer DROP color;Exercise 2.3.1fALTER TABLE Laptop ADD od CHAR (10) DEFAULT none;Exercise 2.3.2aCREATE TABLE Classes (class CHAR(20),type CHAR(5),country CHAR(20),numGuns INTEGER,bore DECIMAL(3,1),

11、displacement INTEGER);Exercise 2.3.2bCREATE TABLE Ships (name CHAR(30),class CHAR(20),launched INTEGER);Exercise 2.3.2cCREATE TABLE Battles (name CHAR(30),date DATE);Exercise 2.3.2dCREATE TABLE Outcomes (ship CHAR(30),battle CHAR(30),result CHAR(10);Exercise 2.3.2eALTER TABLE Classes DROP bore;Exerc

12、ise 2.3.2fALTER TABLE Ships ADD yard CHAR(30);Exercise 2.4.1aR1 := speed 3.00 (PC)R2 := model(R1)model100510061013Exercise 2.4.1bR1 := hd 100 (Laptop)R2 := Product (R1)R3 := maker (R2)makerEABFGExercise 2.4.1cR1 := maker=B (Product PC)R2 := maker=B (Product Laptop)R3 := maker=B (Product Printer)R4 :

13、= model,price (R1)R5 := model,price (R2)R6: = model,price (R3)R7 := R4 R5 R6modelprice100464910056301006104920071429Exercise 2.4.1dR1 := color = true AND type = laser (Printer)R2 := model (R1)model30033007Exercise 2.4.1eR1 := type=laptop (Product)R2 := type=PC(Product)R3 := maker(R1)R4 := maker(R2)R

14、5 := R3 R4makerFGExercise 2.4.1fR1 := PC1(PC)R2 := PC2(PC)R3 := R1 (PC1.hd = PC2.hd AND PC1.model PC2.model) R2R4 := hd(R3)hd25080160Exercise 2.4.1gR1 := PC1(PC)R2 := PC2(PC)R3 := R1 (PC1.speed = PC2.speed AND PC1.ram = PC2.ram AND PC1.model PC2.model) R2R4 := PC1.model,PC2.model(R3)PC1.modelPC2.mod

15、el10041012Exercise 2.4.1hR1 := model(speed 2.80(PC) model(speed 2.80(Laptop)R2 := maker,model(R1 Product)R3 := R3(maker2,model2)(R2)R4 := R2 (maker = maker2 AND model model2) R3R5 := maker(R4)makerBEExercise 2.4.1iR1 := model,speed(PC)R2 := model,speed(Laptop)R3 := R1 R2R4 := R4(model2,speed2)(R3)R5

16、 := model,speed (R3 (speed speed2 ) R4)R6 := R3 R5R7 := maker(R6 Product)makerBExercise 2.4.1jR1 := maker,speed(Product PC)R2 := R2(maker2,speed2)(R1)R3 := R3(maker3,speed3)(R1)R4 := R1 (maker = maker2 AND speed speed2) R2R5 := R4 (maker3 = maker AND speed3 speed2 AND speed3 speed) R3R6 := maker(R5)

17、makerADE Exercise 2.4.1kR1 := maker,model(Product PC)R2 := R2(maker2,model2)(R1)R3 := R3(maker3,model3)(R1)R4 := R4(maker4,model4)(R1)R5 := R1 (maker = maker2 AND model model2) R2R6 := R3 (maker3 = maker AND model3 model2 AND model3 model) R5R7 := R4 (maker4 = maker AND (model4=model OR model4=model

18、2 OR model4=model3) R6R8 := maker(R7)makerABDEExercise 2.4.2aExercise 2.4.2bExercise 2.4.2cExercise 2.4.2dExercise 2.4.2eExercise 2.4.2fExercise 2.4.2gExercise 2.4.2hExercise 2.4.2iExercise 2.4.2jExercise 2.4.2kExercise 2.4.3aR1 := bore 16 (Classes)R2 := class,country (R1)classcountryIowaUSANorth Ca

19、rolinaUSAYamatoJapanExercise 2.4.3bR1 := launched 1921 AND displacement 35000 (R1)R3 := name (R2)nameIowaMissouriMusashiNew JerseyNorth CarolinaWashingtonWisconsinYamatoExercise 2.4.3eR1 := battle=Guadalcanal(Outcomes)R2 := Ships (ship=name) R1R3 := Classes R2R4 := name,displacement,numGuns(R3)named

20、isplacementnumGunsKirishima320008Washington370009Exercise 2.4.3fR1 := name(Ships)R2 := ship(Outcomes)R3 := R3(name)(R2)R4 := R1 R3nameCaliforniaHarunaHieiIowaKirishimaKongoMissouriMusashiNew JerseyNorth CarolinaRamilliesRenownRepulseResolutionRevengeRoyal OakRoyal SovereignTennesseeWashingtonWiscons

21、inYamatoArizonaBismarckDuke of YorkFusoHoodKing George VPrince of WalesRodneyScharnhorstSouth DakotaWest VirginiaYamashiroExercise 2.4.3gFrom 2.3.2, assuming that every class has one ship named after the class.R1 := class(Classes)R2 := class(name class(Ships)R3 := R1 R2classBismarckExercise 2.4.3hR1

22、 := country(type=bb(Classes)R2 := country(type=bc(Classes)R3 := R1 R2countryJapanGt. BritainExercise 2.4.3iR1 := ship,result,date(Battles (battle=name) Outcomes)R2 := R2(ship2,result2,date2)(R1)R3 := R1 (ship=ship2 AND result=damaged AND date date2) R2R4 := ship(R3)No results from sample data.Exerci

23、se 2.4.4aExercise 2.4.4bExercise 2.4.4cExercise 2.4.4dExercise 2.4.4eExercise 2.4.4fExercise 2.4.4gExercise 2.4.4hExercise 2.4.4iExercise 2.4.5The result of the natural join has only one attribute from each pair of equated attributes. On the other hand, the result of the theta-join has both columns

24、of the attributes and their values are identical.Exercise 2.4.6UnionIf we add a tuple to the arguments of the union operator, we will get all of the tuples of the original result and maybe the added tuple. If the added tuple is a duplicate tuple, then the set behavior will eliminate that tuple. Thus

25、 the union operator is monotone.IntersectionIf we add a tuple to the arguments of the intersection operator, we will get all of the tuples of the original result and maybe the added tuple. If the added tuple does not exist in the relation that it is added but does exist in the other relation, then t

26、he result set will include the added tuple. Thus the intersection operator is monotone.DifferenceIf we add a tuple to the arguments of the difference operator, we may not get all of the tuples of the original result. Suppose we have relations R and S and we are computing R S. Suppose also that tuple

27、 t is in R but not in S. The result of R S would include tuple t. However, if we add tuple t to S, then the new result will not have tuple t. Thus the difference operator is not monotone.ProjectionIf we add a tuple to the arguments of the projection operator, we will get all of the tuples of the ori

28、ginal result and the projection of the added tuple. The projection operator only selects columns from the relation and does not affect the rows that are selected. Thus the projection operator is monotone.SelectionIf we add a tuple to the arguments of the selection operator, we will get all of the tu

29、ples of the original result and maybe the added tuple. If the added tuple satisfies the select condition, then it will be added to the new result. The original tuples are included in the new result because they still satisfy the select condition. Thus the selection operator is monotone.Cartesian Pro

30、ductIf we add a tuple to the arguments of the Cartesian product operator, we will get all of the tuples of the original result and possibly additional tuples. The Cartesian product pairs the tuples of one relation with the tuples of another relation. Suppose that we are calculating R x S where R has

31、 m tuples and S has n tuples. If we add a tuple to R that is not already in R, then we expect the result of R x S to have (m + 1) * n tuples. Thus the Cartesian product operator is monotone.Natural JoinsIf we add a tuple to the arguments of a natural join operator, we will get all of the tuples of t

32、he original result and possibly additional tuples. The new tuple can only create additional successful joins, not less. If, however, the added tuple cannot successfully join with any of the existing tuples, then we will have zero additional successful joins. Thus the natural join operator is monoton

33、e.Theta JoinsIf we add a tuple to the arguments of a theta join operator, we will get all of the tuples of the original result and possibly additional tuples. The theta join can be modeled by a Cartesian product followed by a selection on some condition. The new tuple can only create additional tupl

34、es in the result, not less. If, however, the added tuple does not satisfy the select condition, then no additional tuples will be added to the result. Thus the theta join operator is monotone.RenamingIf we add a tuple to the arguments of a renaming operator, we will get all of the tuples of the orig

35、inal result and the added tuple. The renaming operator does not have any effect on whether a tuple is selected or not. In fact, the renaming operator will always return as many tuples as its argument. Thus the renaming operator is monotone.Exercise 2.4.7aIf all the tuples of R and S are different, t

36、hen 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. Then the union has max(m , n) tuples. Exercise 2.4.7bIf all the tuples in one relation can pair successf

37、ully with all the tuples in the other relation, then the natural join has n * m tuples. This number would be the maximum possible.The minimum number of tuples that can appear in the result occurs if none of the tuples of one relation can pair successfully with all the tuples in the other relation. T

38、hen the natural join has zero tuples.Exercise 2.4.7cIf the condition C brings back all the tuples of R, then the cross product will contain n * m tuples. This number would be the maximum possible.The minimum number of tuples that can appear in the result occurs if the condition C brings back none of

39、 the tuples of R. Then the cross product has zero tuples.Exercise 2.4.7dAssuming that the list of attributes L makes the resulting relation L(R) and relation S schema compatible, then the maximum possible tuples is n. This happens when all of the tuples of L(R) are not in S.The minimum number of tup

40、les that can appear in the result occurs when all of the tuples in L(R) appear in S. Then the difference has max(n m , 0) tuples. Exercise 2.4.8Defining r as the schema of R and s as the schema of S:1. r(R S)2. R (rs(S)where is the duplicate-elimination operator in Section 5.2 pg. 2133. R (R r(R S)E

41、xercise 2.4.9Defining r as the schema of R1. R - r(R S)Exercise 2.4.10A1,A2An(R S)Exercise 2.5.1aspeed 500(PC) = Model 1011 violates this constraint.Exercise 2.5.1bscreen 15.4 AND hd 100 AND price 1000(Laptop) = Model 2004 violates the constraint.Exercise 2.5.1cmaker(type = laptop(Product) maker(typ

42、e = pc(Product) = Manufacturers A,B,E violate the constraint.Exercise 2.5.1dThis complex expression is best seen as a sequence of steps in which we define temporary relations R1 through R4 that stand for nodes of expression trees. Here is the sequence: R1(maker, model, speed) := maker,model,speed(Product PC) R2(maker, speed) := maker,speed(Product Laptop) R3(model) := model(R1 R1.maker = R2.maker AND R1.speed R2.speed R2) R4(model) := model(PC)The constraint is R4 R3Manufacturers B,C,D violate the constraint.

展开阅读全文
相关资源
相关搜索

当前位置:首页 > 教育专区 > 教案示例

本站为文档C TO C交易模式,本站只提供存储空间、用户上传的文档直接被用户下载,本站只是中间服务平台,本站所有文档下载所得的收益归上传人(含作者)所有。本站仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。若文档所含内容侵犯了您的版权或隐私,请立即通知淘文阁网,我们立即给予删除!客服QQ:136780468 微信:18945177775 电话:18904686070

工信部备案号:黑ICP备15003705号© 2020-2023 www.taowenge.com 淘文阁