2022年数据库系统基础教程第八章答案 .pdf
《2022年数据库系统基础教程第八章答案 .pdf》由会员分享,可在线阅读,更多相关《2022年数据库系统基础教程第八章答案 .pdf(7页珍藏版)》请在淘文阁 - 分享文档赚钱的网站上搜索。
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
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 2022年数据库系统基础教程第八章答案 2022 数据库 系统 基础教程 第八 答案
限制150内