数据库系统基础教程第八章答案(共7页)_第1页
数据库系统基础教程第八章答案(共7页)_第2页
数据库系统基础教程第八章答案(共7页)_第3页
数据库系统基础教程第八章答案(共7页)_第4页
数据库系统基础教程第八章答案(共7页)_第5页
已阅读5页,还剩2页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

1、精选优质文档-倾情为你奉上Section 1Exercise 8.1.1a)CREATE VIEW RichExec AS SELECT * FROM MovieExec WHERE netWorth >= ;b)CREATE VIEW StudioPres (name, address, cert#) ASSELECT MovieE, MovieExec.address, MovieExec.cert# FROM MovieExec, Studio WHERE MovieExec.cert# = Studio.presC#;c)CREATE VIEW Executive

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

3、SELECT RichE from RichExec, StudioPres where RichE = StudioP;c)SELECT ExecutiveS from ExecutiveStar, StudioPres WHERE ExecutiveSWorth >= AND StudioPres.cert# = RichExec.cert#;Section 2Exercise 8.2.1The views RichExec and StudioPres are updatable; however, the Studi

4、oPres view needs to be created with a subquery.CREATE VIEW StudioPres (name, address, cert#) ASSELECT MovieE, MovieExec.address, MovieExec.cert# FROM MovieExec WHERE MovieExec.cert# IN (SELECT presCt# from Studio);Exercise 8.2.2a) Yes, the view is updatable.b)CREATE TRIGGER DisneyComedyInser

5、t INSTEAD OF INSERT ON DisneyComedies REFERENCING NEW ROW AS NewRowFOR EACH ROWINSERT INTO Movies(title, year, length, studioName, genre)VALUES(NewRow.title, NewRow.year, NewYear.length, Disney, comedy);c)CREATE TRIGGER DisneyComedyUpdate INSTEAD OF UPDATE ON DisneyComedies REFERENCING NEW ROW AS Ne

6、wRowFOR EACH ROWUPDATE Movies SET length NewRow.lengthWHERE title = NewRow.title AND year = NEWROW.year ANDstudionName = Disney AND genre = comedy;Exercise 8.2.3a) No, the view is not updatable since it is constructed from two different relations.b)CREATE TRIGGER NewPCInsertINSTEAD OF INSERT ON NewP

7、CREFERENCING NEW ROW AS NewRowFOR EACH ROW(INSERT INTO Product VALUES(NewRow.maker, NewRow.model, pc)(INSERT INTO PC VALUES(NewRow.model, NewRow.speed, NewRow.ram, NewRow.hd, NewRow.price);c)CREATE TRIGGER NewPCUpdateINSTEAD OF UPDATE ON NewPCREFERENCING NEW ROW AS NewRowFOR EACH ROWUPDATE PC SET pr

8、ice = NewPC.price where model = NewPC.model;d)CREATE TRIGGER NewPCDeleteINSTEAD OF DELETE ON NeePCREFERENCING OLD ROW AS OldRowFOR EACH ROW(DELETE FROM Product WHERE model = OldRow.model)(DELETE FROM PC where model = OldRow.model);Section 3Exercise 8.3.1a)CREATE INDEX NameIndex on Studio(name);b)CRE

9、ATE INDEX AddressIndex on MovieExec(address);c)CREATE INDEX GenreIndex on Movies(genre, length);Section 4Exercise 8.4.1ActionNo IndexStar IndexMovie IndexBoth IndexesQ110041004Q210010044I2446Average2 + 98p1 + 98p24 + 96 p24 + 96 p16 2 p1 2 p2Exercise 8.4.2Q1 = SELECT * FROM Ships WHERE name = n;Q2 =

10、 SELECT * FROM Ships WHERE class = c;Q3 = SELECT * FROM Ships WHERE launched = y;I = InsertsIndexesActionsNoneNameClass Launched Name & Class Name & Launched Class & Launched Three IndexesQ1502505022502Q21121212 2Q35050502650262626I24446668Average2 + 48p1 -p2 + 48p34 + 46 p3 - 2 p1 - 3 p

11、24 + 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.Section 5Exercise 8.5.1Updates to movies that involves title or yearUPD

12、ATE MovieProd SET title = newTitle where title=oldTitle AND year = oldYear;UPDATE MovieProd SET year = newYear where title=oldYitle AND year = oldYear;Update to MovieExec involving cert#DELETE FROM MovieProd WHERE (title, year) IN (SELECT title, year FROM Movies, MovieExec WHERE cert# = oldCert# AND

13、 cert# = producerC#);INSERT INTO MovieProd SELECT title, year, name FROM Movies, MovieExec WHERE cert# = newCert# AND cert# = producerC#;Exercise 8.5.2Insertions, deletions, and updates to the base tables Product and PC would require a modification of the materialized view.Insertions into Product wi

14、th type equal to pc:INSERT INTO NewPC SELECT maker, model, speed, ram, hd, price FROM Product, PC WHERE Product.model = newModel and Product.model = PC.model;Insertions into PC:INSERT INTO NewPC SELECT maker, newModel, newSpeed, newRam, newHd, newPrice FROM Product WHERE model = newModel;Deletions f

15、rom Product with type equal to pc:DELETE FROM NewPC WHERE maker = deletedMaker AND model=deletedModel;Deletions from PC: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 attribut

16、e model needs to be treated as 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.3Modifications to the base tables that would require a modification to the materialized view: inserts and delete

17、s from Ships, deletes from class, updates to a Class displacement.Deletions from Ship:UPDATE ShipStats SETdisplacement=(displacement * count) (SELECT displacement FROM Classses WHERE class = DeletedShipClass) / (count 1),count = count 1WHEREcountry = (SELECT country FROM Classes WHERE class=DeletedS

18、hipClass);Insertions into Ship:Update ShipStat SETdisplacement=(displacement*count) + (SELECT displacement FROM Classes WHERE class=InsertedShipClass) / (count + 1),count = count + 1WHEREcountry = (SELECT country FROM Classes WHERE classes=InsertedShipClass);Deletes from Classes:NumRowsDeleted = SEL

19、ECT count(*) FROM ships WHERE class = DeletedClass;UPDATE ShipStats SETdisplacement = (displacement * count) - (DeletedClassDisplacement * NumRowsDeleted) / (count NumRowsDeleted),count = count NumRowsDeletedWHERE country = DeletedClassCountry;Update to a Class displacement:N = SELECT count(*) FROM

20、Ships where class = UpdatedClass;UPDATE ShipsStat SETdisplacement = (displacement * count) + (oldDisplacement newDisplacement) * N)/countWHEREcountry = UpdatedClassCountry;Exercise 8.5.4Queries that can be rewritten with the materialized view:Names of stars of movies produced by a certain producer S

21、ELECT starNameFROM StarsIn, Movies, MovieExecWHERE movieTitle = title AND movieYear = year AND producerC# = cert# AND name = Max Bialystock;Movies produced by a certain producerSELECT title, year FROM Movies, MovieExecWhere producerC# = cert# AND name = George Lucas;Names of producers that a certain star has worked withSELECT nameFROM Movies, MovieExec, StarsInWhere producerC#=cert# AND title=movieTitle AND year=movieYear AND

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论