2022年数据库系统基础教程第八章答案 .pdf

上传人:Q****o 文档编号:25952012 上传时间:2022-07-14 格式:PDF 页数:7 大小:55.75KB
返回 下载 相关 举报
2022年数据库系统基础教程第八章答案 .pdf_第1页
第1页 / 共7页
2022年数据库系统基础教程第八章答案 .pdf_第2页
第2页 / 共7页
点击查看更多>>
资源描述

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

1、Section 1 Exercise 8.1.1 a) CREATE VIEW RichExec AS SELECT * FROM MovieExec WHERE netWorth = 10000000; b) CREATE VIEW StudioPres (name, address, cert#) AS SELECT MovieExec.name, MovieExec.address, MovieExec.cert# FROM MovieExec, Studio WHERE MovieExec.cert# = Studio.presC#; c) CREATE VIEW ExecutiveS

2、tar (name, address, gender, birthdate, cert#, netWorth) AS SELECT star.name, star.address, star.gender, star.birthdate, exec.cert#, Worth FROM MovieStar star, MovieExec exec WHERE star.name = exec.name AND star.address = exec.address; Exercise 8.1.2 a) SELECT name from ExecutiveStar WHERE gender = f

3、 ;b) SELECT RichExec.name from RichExec, StudioPres where RichExec.name = StudioPres.name; c) SELECT ExecutiveStar.name from ExecutiveStar, StudioPres WHERE ExecutiveSWorth = 50000000 AND StudioPres.cert# = RichExec.cert#; Section 2 Exercise 8.2.1 The views RichExec and StudioPres are updatable; how

4、ever, the StudioPres view needs to be created with a subquery. CREATE VIEW StudioPres (name, address, cert#) AS SELECT MovieExec.name, MovieExec.address, MovieExec.cert# FROM MovieExec WHERE MovieExec.cert# IN (SELECT presCt# from Studio); Exercise 8.2.2 a) Yes, the view is updatable. b) 名师资料总结 - -

5、-精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 1 页,共 7 页 - - - - - - - - - CREATE TRIGGER DisneyComedyInsert INSTEAD OF INSERT ON DisneyComedies REFERENCING NEW ROW AS NewRow FOR EACH ROW INSERT INTO Movies(title, year, length, studioName, genre) VALUES(NewRow.title, NewRow.yea

6、r, NewYear.length, Disney , comedy);c) CREATE TRIGGER DisneyComedyUpdate INSTEAD OF UPDATE ON DisneyComedies REFERENCING NEW ROW AS NewRow FOR EACH ROW UPDATE Movies SET length NewRow.length WHERE title = NewRow.title AND year = NEWROW.year AND studionName = Disney AND genre = comedy;Exercise 8.2.3

7、a) No, the view is not updatable since it is constructed from two different relations. b) CREATE TRIGGER NewPCInsert INSTEAD OF INSERT ON NewPC REFERENCING NEW ROW AS NewRow FOR EACH ROW (INSERT INTO Product VALUES(NewRow.maker, NewRow.model, pc) (INSERT INTO PC VALUES(NewRow.model, NewRow.speed, Ne

8、wRow.ram, NewRow.hd, NewRow.price); c) CREATE TRIGGER NewPCUpdate INSTEAD OF UPDATE ON NewPC REFERENCING NEW ROW AS NewRow FOR EACH ROW UPDATE PC SET price = NewPC.price where model = NewPC.model; d) CREATE TRIGGER NewPCDelete INSTEAD OF DELETE ON NeePC REFERENCING OLD ROW AS OldRow FOR EACH ROW (DE

9、LETE FROM Product WHERE model = OldRow.model) (DELETE FROM PC where model = OldRow.model); Section 3 名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 2 页,共 7 页 - - - - - - - - - Exercise 8.3.1 a) CREATE INDEX NameIndex on Studio(name); b) CREATE INDEX AddressIndex on M

10、ovieExec(address); c) CREATE INDEX GenreIndex on Movies(genre, length); Section 4 Exercise 8.4.1 Action No Index Star Index Movie Index Both Indexes Q1 100 4 100 4 Q2 100 100 4 4 I 2 4 4 6 Average 2 + 98p1 + 98p2 4 + 96 p24 + 96 p16 2 p1 2 p2Exercise 8.4.2 Q1 = SELECT * FROM Ships WHERE name = n; Q2

11、 = SELECT * FROM Ships WHERE class = c; Q3 = SELECT * FROM Ships WHERE launched = y; I = Inserts Indexes Actions None Name Class Launched Name & Class Name & Launched Class & Launched Three Indexes Q1 50 2 50 50 2 2 50 2 Q2 1 1 2 1 2 1 2 2 Q3 50 50 50 26 50 26 26 26 I 2 4 4 4 6 6 6 8 Average 2 + 48p

12、1 -p2 + 48p3 4 + 46 p3- 2 p1 - 3 p24 + 46p1 - 2p2 + 46p34 + 46p1- 3p2 + 22p36 - 4p1- 4p2 + 44p36 - 4p1 - 5p2 + 20p36 - 44p1 - 4p2 + 20p38 - 6p1 - 6p2 + 18p3The best choice of indexes (name and launched) has an average cost of 6 - 4p1 - 5p2 + 20p3 per operation. 名师资料总结 - - -精品资料欢迎下载 - - - - - - - - -

13、 - - - - - - - - - 名师精心整理 - - - - - - - 第 3 页,共 7 页 - - - - - - - - - Section 5Exercise 8.5.1 Updates to movies that involves title or year UPDATE MovieProd SET title = newTitle where title=oldTitle AND year = oldYear; UPDATE MovieProd SET year = newYear where title=oldYitle AND year = oldYear;Updat

14、e to MovieExec involving cert# DELETE FROM MovieProd WHERE (title, year) IN ( SELECT title, year FROM Movies, MovieExec WHERE cert# = oldCert# AND cert# = producerC# ); INSERT INTO MovieProd SELECT title, year, name FROM Movies, MovieExec WHERE cert# = newCert# AND cert# = producerC#; Exercise 8.5.2

15、 Insertions, deletions, and updates to the base tables Product and PC would require a modification of the materialized view. Insertions into Product with type equal to pc:INSERT INTO NewPC SELECT maker, model, speed, ram, hd, price FROM Product, PC WHERE Product.model = newModel and Product.model =

16、PC.model; Insertions into PC: INSERT INTO NewPC SELECT maker, newModel, newSpeed , newRam , newHd , newPrice FROM Product WHERE model = newModel;Deletions from Product with type equal to pc:DELETE FROM NewPC WHERE maker = deletedMaker AND model= deletedModel ;Deletions from PC: 名师资料总结 - - -精品资料欢迎下载

17、- - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 4 页,共 7 页 - - - - - - - - - DELETE FROM NewPC WHERE model = deletedModel ;Updates to PC: Update NewPC SET speed=PC.speed, ram=PC.ram, hd=PC.hd, price=PC.price FROM PC where model=pc.model; Update to the attribute model needs to be treated as

18、 a delete and an insert. Updates to Product: Any changes to a Product tuple whose type is pc need to be treated as a delete or an insert, or both. Exercise 8.5.3 Modifications to the base tables that would require a modification to the materialized view: inserts and deletes from Ships, deletes from

19、class, updates to a Class displacement. Deletions from Ship: UPDATE ShipStats SET displacement=(displacement * count) (SELECT displacement FROM Classses WHERE class = DeletedShipClass) / (count 1), count = count 1 WHERE country = (SELECT country FROM Classes WHERE class= DeletedShipClass);Insertions

20、 into Ship: Update ShipStat SET displacement=(displacement*count) + (SELECT displacement FROM Classes WHERE class= InsertedShipClass) / (count + 1), count = count + 1 WHERE country = (SELECT country FROM Classes WHERE classes=InsertedShipClass);Deletes from Classes: NumRowsDeleted = SELECT count(*)

21、FROM ships WHERE class = DeletedClass;UPDATE ShipStats SET displacement = (displacement * count) - (DeletedClassDisplacement * 名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 5 页,共 7 页 - - - - - - - - - NumRowsDeleted) / (count NumRowsDeleted), count = count NumRowsDe

22、leted WHERE country = DeletedClassCountry;Update to a Class displacement:N = SELECT count(*) FROM Ships where class = UpdatedClass ;UPDATE ShipsStat SET displacement = (displacement * count) + (oldDisplacement newDisplacement) * N)/count WHERE country = UpdatedClassCountry;Exercise 8.5.4 Queries tha

23、t can be rewritten with the materialized view: Names of stars of movies produced by a certain producer SELECT starName FROM StarsIn, Movies, MovieExec WHERE movieTitle = title AND movieYear = year AND producerC# = cert# AND name = Max Bialystock;Movies produced by a certain producer SELECT title, ye

24、ar FROM Movies, MovieExec Where produce rC# = cert# AND name = George Lucas ; Names of producers that a certain star has worked with SELECT name FROM Movies, MovieExec, StarsIn Where producerC#=cert# AND title=movieTitle AND year=movieYear AND starName=Carrie Fisher;The number of movies produced by

25、given producer SELECT count(*) FROM Movies, MovieExec WHERE producerC#=cert# AND name = George Lucas ;Names of producers who also starred in their own movies 名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 6 页,共 7 页 - - - - - - - - - SELECT name FROM Movies, StarsIn,

26、MovieExec WHERE producerC#=cert# AND movieTitle = title AND movieYear = year AND MovieExec.name = starName; The number of stars that have starred in movies produced by a certain producer SELECT count(DISTINCT starName) FROM Movies, StarsIn, MovieExec WHERE producerC#=cert# AND movieTitle = title AND movieYear = year AND name George Lucas ;The number of movies produced by each producer SELECT name, count(*) FROM Movies, MovieExec WHERE producerC#=cert# GROUP BY name 名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 7 页,共 7 页 - - - - - - - - -

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

当前位置:首页 > 技术资料 > 技术总结

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

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