數(shù)據(jù)庫(kù)系統(tǒng)基礎(chǔ)教程第八章答案_第1頁(yè)
數(shù)據(jù)庫(kù)系統(tǒng)基礎(chǔ)教程第八章答案_第2頁(yè)
數(shù)據(jù)庫(kù)系統(tǒng)基礎(chǔ)教程第八章答案_第3頁(yè)
數(shù)據(jù)庫(kù)系統(tǒng)基礎(chǔ)教程第八章答案_第4頁(yè)
數(shù)據(jù)庫(kù)系統(tǒng)基礎(chǔ)教程第八章答案_第5頁(yè)
已閱讀5頁(yè),還剩2頁(yè)未讀, 繼續(xù)免費(fèi)閱讀

下載本文檔

版權(quán)說(shuō)明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)

文檔簡(jiǎn)介

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. 本站所有資源如無(wú)特殊說(shuō)明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁(yè)內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒(méi)有圖紙預(yù)覽就沒(méi)有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫(kù)網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。

評(píng)論

0/150

提交評(píng)論