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

下载本文档

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

文档简介

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

2、, 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;a)SELECT name from ExecutiveStar WHERE gender = f;b)SELECT RichE from RichExe

3、c, StudioPres where RichE = StudioP;c)SELECT ExecutiveS from ExecutiveStar, StudioPres WHERE ExecutiveSWorth >= 50000000 AND StudioPres.cert# = RichExec.cert#;Section 2The views RichExec and StudioPres are updatable; however, the StudioPres view needs to be created with a

4、subquery.CREATE VIEW StudioPres (name, address, cert#) ASSELECT MovieE, MovieExec.address, MovieExec.cert# FROM MovieExec WHERE MovieExec.cert# IN (SELECT presCt# from Studio);a) Yes, the view is updatable.b)CREATE TRIGGER DisneyComedyInsert INSTEAD OF INSERT ON DisneyComedies REFERENCING NE

5、W 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 NewRowFOR EACH ROWUPDATE Movies SET length NewRow.leng

6、thWHERE title = NewRow.title AND year = NEWROW.year ANDstudionName = Disney AND genre = comedy;a) No, the view is not updatable since it is constructed from two different relations.b)CREATE TRIGGER NewPCInsertINSTEAD OF INSERT ON NewPCREFERENCING NEW ROW AS NewRowFOR EACH ROW(INSERT INTO Product VAL

7、UES(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 price = NewPC.price where model = NewPC.model;d)CREATE TRIGGER NewPC

8、DeleteINSTEAD 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 3a)CREATE INDEX NameIndex on Studio(name);b)CREATE INDEX AddressIndex on MovieExec(address);c)CREATE INDEX GenreIndex on Movies

9、(genre, length);Section 4ActionNo IndexStar IndexMovie IndexBoth IndexesQ110041004Q210010044I2446Average2 + 98p1 + 98p24 + 96 p24 + 96 p16 2 p1 2 p2Q1 = SELECT * FROM Ships WHERE name = n;Q2 = SELECT * FROM Ships WHERE class = c;Q3 = SELECT * FROM Ships WHERE launched = y;I = InsertsIndexesActionsNo

10、neNameClass Launched Name & Class Name & Launched Class & Launched Three IndexesQ1502505022502Q21121212 2Q35050502650262626I24446668Average2 + 48p1 -p2 + 48p34 + 46 p3 - 2 p1 - 3 p24 + 46p1 - 2p2 + 46p34 + 46p1 - 3p2 + 22p36 - 4p1 - 4p2 + 44p36 - 4p1 - 5p2 + 20p36 - 44p1 - 4p2 + 20p38 -

11、6p1 - 6p2 + 18p3The best choice of indexes (name and launched) has an average cost of 6 - 4p1 - 5p2 + 20p3 per operation.Section 5Updates to movies that involves title or yearUPDATE MovieProd SET title = newTitle where title=oldTitle AND year = oldYear;UPDATE MovieProd SET year = newYear where title

12、=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 cert# = producerC#);INSERT INTO MovieProd SELECT title, year, name FROM Movies, MovieExec WHERE cert# = newCert# AND cert

13、# = producerC#;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 Pro

14、duct.model = 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:DELETE FROM NewP

15、C 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 a delete and an insert. Updates to Product:Any changes to a Product tuple whose type is pc need to be tre

16、ated as a delete or an insert, or both.Modifications to the base tables that would require a modification to the materialized view: inserts and deletes from Ships, deletes from class, updates to a Class displacement.Deletions from Ship:UPDATE ShipStats SETdisplacement=(displacement * count) (SELECT

17、displacement FROM Classses WHERE class = DeletedShipClass) / (count 1),count = count 1WHEREcountry = (SELECT country FROM Classes WHERE class=DeletedShipClass);Insertions into Ship:Update ShipStat SETdisplacement=(displacement*count) + (SELECT displacement FROM Classes WHERE class=InsertedShipClass)

18、 / (count + 1),count = count + 1WHEREcountry = (SELECT country FROM Classes WHERE classes=InsertedShipClass);Deletes from Classes:NumRowsDeleted = SELECT count(*) FROM ships WHERE class = DeletedClass;UPDATE ShipStats SETdisplacement = (displacement * count) - (DeletedClassDisplacement * NumRowsDele

19、ted) / (count NumRowsDeleted),count = count NumRowsDeletedWHERE country = DeletedClassCountry;Update to a Class displacement:N = SELECT count(*) FROM Ships where class = UpdatedClass;UPDATE ShipsStat SETdisplacement = (displacement * count) + (oldDisplacement newDisplacement) * N)/countWHEREcountry

20、= UpdatedClassCountry;Queries that can be rewritten with the materialized view:Names of stars of movies produced by a certain producer SELECT 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 starName

温馨提示

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

评论

0/150

提交评论