欢迎来到淘文阁 - 分享文档赚钱的网站! | 帮助中心 好文档才是您的得力助手!
淘文阁 - 分享文档赚钱的网站
全部分类
  • 研究报告>
  • 管理文献>
  • 标准材料>
  • 技术资料>
  • 教育专区>
  • 应用文书>
  • 生活休闲>
  • 考试试题>
  • pptx模板>
  • 工商注册>
  • 期刊短文>
  • 图片设计>
  • ImageVerifierCode 换一换

    数据库系统基础教程第七章答案.pdf

    • 资源ID:21132537       资源大小:472.63KB        全文页数:17页
    • 资源格式: PDF        下载积分:10金币
    快捷下载 游客一键下载
    会员登录下载
    微信登录下载
    三方登录下载: 微信开放平台登录   QQ登录  
    二维码
    微信扫一扫登录
    下载资源需要10金币
    邮箱/手机:
    温馨提示:
    快捷下载时,用户名和密码都是您填写的邮箱或者手机号,方便查询和重复下载(系统自动生成)。
    如填写123,账号就是123,密码也是123。
    支付方式: 支付宝    微信支付   
    验证码:   换一换

     
    账号:
    密码:
    验证码:   换一换
      忘记密码?
        
    友情提示
    2、PDF文件下载后,可能会被浏览器默认打开,此种情况可以点击浏览器菜单,保存网页到桌面,就可以正常下载了。
    3、本站不支持迅雷下载,请使用电脑自带的IE浏览器,或者360浏览器、谷歌浏览器下载即可。
    4、本站资源下载后的文档和图纸-无水印,预览文档经过压缩,下载后原文更清晰。
    5、试题试卷类文档,如果标题没有明确说明有答案则都视为没有答案,请知晓。

    数据库系统基础教程第七章答案.pdf

    SolutionsChapter 77.1.17.1.1a)CREATE TABLE Movies (titleCHAR(100),yearINT,lengthINT,genreCHAR(10),studioNameCHAR(30),producerC#INT,PRIMARY KEY (title, year),FOREIGN KEY (producerC#) REFERENCES MovieExec(cert#);orCREATE TABLE Movies (titleCHAR(100),yearINT,lengthINT,genreCHAR(10),studioNameCHAR(30),producerC#INTREFERENCES MovieExec(cert#),PRIMARY KEY (title, year);b)CREATE TABLE Movies (titleCHAR(100),yearINT,lengthINT,genreCHAR(10),studioNameCHAR(30),producerC#INTREFERENCES MovieExec(cert#)ON DELETE SET NULLON UPDATE SET NULL,PRIMARY KEY (title, year);c)CREATE TABLE Movies (titleCHAR(100),yearINT,lengthINT,genreCHAR(10),studioNameCHAR(30),producerC#INTREFERENCES MovieExec(cert#)ON DELETE CASCADEON UPDATE CASCADE,PRIMARY KEY (title, year);d)CREATE TABLE StarsIn (movieTitleCHAR(100) REFERENCES Movie(title),movieYearINT,starNameCHAR(30),PRIMARY KEY (movieTItle, movieYear, starName);e)CREATE TABLE StarsIn (movieTitleCHAR(100) REFERENCES Movie(title)ON DELETE CASCADE,movieYearINT,starNameCHAR(30),PRIMARY KEY (movieTItle, movieYear, starName);7.1.27.1.2Todeclaresuchaforeign-keyconstraintbetweentherelationsMovieandStarsIn,valuesofthereferencingattributesinMovieshouldappearinMovieStarasuniquevalues.However,basedonprimarykeydeclaration in relation StarIn, the uniqueness of movies is guaranteedwithmovieTitle,movieYear,andstarNameattributes.Evenwithtitleandyearasreferencingattributesthereisnowayofreferencingunique movie from StarsIn without starName information. Therefore, sucha constraint can not be expressed using a foreign-key constraint.7.1.37.1.3ALTER TABLE ProductADD PRIMARY KEY (model);ALTER TABLE PCADD FOREIGN KEY (model) REFERENCES Product (model);ALTER TABLE LaptopADD FOREIGN KEY (model) REFERENCES Product(model);ALTER TABLE PrinterADD FOREIGN KEY (model) REFERENCES Product (model);7.1.47.1.4ALTER TABLE ClassesADD PRIMARY KEY (class);ALTER TABLE ShipsADD PRIMARY KEY (name);ALTER TABLE ShipsADD FOREIGN KEY (class) REFERENCES Classes (calss);ALTER TABLE BattlesADD PRIMARY KEY (name);ALTER TABLE OutcomesADD FOREIGN KEY (ship) REFERENCES Ships (name);ALTER TABLE OutcomesADD FOREIGN KEY (battle) REFERENCES Battles (name);7.1.5a)ALTER TABLE ShipsADD FOREIGN KEY (class) REFERENCES Classes (class) ON DELETE SET NULL ON UPDATE SET NULL;In addition to the above declaration, class must be declared theprimary key for Classes.b)ALTER TABLE OutcomeADD FOREIGN KEY (battle) REFERENCES Battles (name) ON DELETE SET NULL ON UPDATE SET NULL;c)ALTER TABLE OutcomesADD FOREIGN KEY (ship) REFERENCES Ships (name) ON DELETE SET NULL ON UPDATE SET NULL;7.2.17.2.1a)yearINTCHECK (year = 1915)b)lengthINTCHECK (length = 60 AND length = 2.0);b)CREATE TABLE Printer ( typeVARCHAR(10) CHECK (type IN (laser, ink-jet, bubble-jet);c)CREATE TABLE Product ( typeVARCHAR(10) CHECK (type IN(pc, laptop, printer);d)CREATE TABLE Product ( modelCHAR(4) CHECK (model IN (SELECT model FROM PCUNION ALL SELECT model FROM laptopUNION ALL SELECT model FROM printer);* note this doesnt check the attribute constraint violation caused bydeletions from PC, laptop, or printer7.2.37.2.3a)CREATE TABLE StarsIn ( starName CHAR(30) CHECK (starName IN (SELECT name FROM MovieStar WHERE YEAR(birthdate) movieYear);b)CREATE TABLE Studio ( address CHAR(255)CHECK (address IS UNIQUE);c)CREATE TABLE MovieStar ( name CHAR(30)CHECK (name NOT IN (SELECT name FROM MovieExec);d)CREATE TABLE Studio (Name CHAR(30)CHECK (name IN (SELECT studioName FROM Movies);e)CREATE TABLE Movies (CHECK (producerC# NOT IN (SELECT presC# FROM Studio) OR studioName IN (SELECT name FROM Studio WHERE presC# = producerC#);7.2.47.2.4a)CHECK (speed = 2.0 OR price = 15 OR hd = 40 OR price 16)b)CHECK (class NOT IN (SELECT class FROM ClassesWHERE numGuns 9 AND bore 14)c) CHECK (ship IN (SELECT s.name FROM Ships s, Battles b, Outcomes o WHERE s.name = o.ship AND b.name = o.battle AND s.launched YEAR(b.date)7.2.6The constraint in Example 7.6 does not allow NULL value for genderwhile the constraint in Example 7.8 allows NULL.7.3.17.3.1a)ALTER TABLE Movie ADD CONSTRAINT myKeyPRIMARY KEY (title, year);b)ALTER TABLE Movie ADD CONSTRAINT producerCheckFOREIGN KEY (producerC#) REFERENCES MovieExec (cert#);c)ALTER TABLE Movie ADD CONSTRAINT lengthCheckCHECK (length = 60 AND length 14);e)ALTER TABLE Ships ADD CONSTRAINT shipDateCheck CHECK (ship IN (SELECT s.name FROM Ships s, Battles b, Outcomes o WHERE s.name = o.ship AND b.name = o.battle AND s.launched = YEAR(b.date)7.4.1a)CREATE ASSERTION CHECK (NOT EXISTS ( (SELECT maker FROM Product NATURAL JOIN PC) INTERSECT (SELECT maker FROM Product NATURAL JOIN Laptop) ) );b)CREATE ASSERTION CHECK (NOT EXISTS (SELECT maker FROM Product NATURAL JOIN PC WHERE speed ALL (SELECT L2.speed FROM Product P2, Laptop L2 WHERE P2.maker = maker AND P2.model = L2.model ) ) );c)CREATE ASSERTION CHECK (NOT EXISTS (SELECT model FROM Laptop WHERE price = ALL(SELECT price FROM PC WHERE PC.ram = ALL(SELECT COUNT(*) FROM Ships GROUP BY class) );b)CREATE ASSERTION CHECK (NOT EXISTS(SELECT country FROM ClassesWHERE type = bb )INTERSECT(SELECT country FROM ClassesWHERE type = bc ) );c)CREATE ASSERTION CHECK (NOT EXISTS(SELECT o.battle FROM Outcomes o, Ships s, Classes c WHERE o.ship = s.name AND s.class = c.class AND c.numGuns 9 ) INTERSECT(SELECT o.battle FROM Outcomes o, Ships s, Classes cWHERE o.result = sunk AND o.ship = s.name AND s.class = c.class AND c.numGuns 9 ) );d)CREATE ASSERTION CHECK (NOT EXISTS(SELECT s1.name FROM Ships s1 WHERE s1.launched = 10000000 )2)presC# INT Check(presC# NOT IN (SELECT cert# FROM MovieExec WHERE netWorth (SELECT AVG(netWorth) FROM MovieExec)DELETE FROM MovieExecWHERE (name, address, cert#, netWorth) IN NewStuff;CREATE TRIGGER AvgNetWorthTriggerAFTER DELETE ON MovieExecREFERENCINGOLD TABLE AS OldStuffFOR EACH STATEMENTWHEN (500000 (SELECT AVG(netWorth) FROM MovieExec)INSERT INTO MovieExec(SELECT * FROM OldStuff);7.5.27.5.2a)CREATE TRIGGER LowPricePCTriggerAFTER UPDATE OF price ON PCREFERENCINGOLD ROW AS OldRow,OLD TABLE AS OldStuff,NEW ROW AS NewRow,NEW TABLE AS NewStuffFOR EACH ROWWHEN (NewRow.price (SELECT AVG(price) FROM Laptop)BEGINDELETE FROM LaptopWHERE (model, speed, ram, hd, screen, price) IN NewStuff;INSERT INTO Laptop(SELECT * FROM OldStuff);END;d)CREATE TRIGGER HardDiskTriggerAFTER UPDATE OF hd, ram ON PCREFERENCINGOLD ROW AS OldRow,OLD TABLE AS OldStuff,NEW ROW AS NewRow,NEW TABLE AS NewStuffFOR EACH ROWWHEN (NewRow.hd 35000)UPDATE NewStuff SET displacement = 35000;c)CREATE TRIGGER newOutcomesTriggerAFTER INSERT ON OutcomesREFERENCINGNEW ROW AS NewRowFOR EACH ROWWHEN (NewRow.ship NOT EXISTS (SELECT name FROM Ships)INSERT INTO Ships (name, class, lunched)VALUES (NewRow.ship, NULL, NULL);CREATE TRIGGER newOutcomesTrigger2AFTER INSERT ON OutcomesREFERENCINGNEW ROW AS NewRowFOR EACH ROWWHEN (NewRow.battle NOT EXISTS (SELECT name FROM Battles)INSERT INTO Battles (name, date)VALUES (NewRow.battle, NULL);d)CREATE TRIGGER changeShipTriggerAFTER INSERT ON ShipsREFERENCINGNEW TABLE AS NewStuffFOR EACH STATEMENTWHEN ( 20 ALL(SELECT COUNT(name) From Ships NATURAL JOIN ClassesGROUP BY country)DELETE FROM ShipsWHERE (name, class, launched) IN NewStuff;CREATE TRIGGER changeShipTrigger2AFTER UPDATE ON ShipsREFERENCINGOLD TABLE AS OldStuff,NEW TABLE AS NewStuffFOR EACH STATEMENTWHEN ( 20 ALL(SELECT COUNT(name) From Ships NATURAL JOIN ClassesGROUP BY country)BEGINDELETE FROM ShipsWHERE (name, class, launched) IN NewStuff;INSERT INTO Ships(SELECT * FROM OldStuff);END;e)CREATE TRIGGER sunkShipTriggerAFTER INSERT ON OutcomesREFERENCINGNEW ROW AS NewRowNEW TABLE AS NewStuffFOR EACH ROWWHEN ( (SELECT date FROM Battles WHERE name = NewRow.battle) ALL(SELECT date FROM Battles WHERE name IN (SELECT battle FROM Outcomes WHERE ship = NewRow.ship ANDresult = “sunk” ) ) )DELETE FROM OutcomesWHERE (ship, battle, result) IN NewStuff;CREATE TRIGGER sunkShipTrigger2AFTER UPDATE ON OutcomesREFERENCINGNEW ROW AS NewRow,NEW TABLE AS NewStuffFOR EACH ROWFOR EACH ROWWHEN ( (SELECT date FROM Battles WHERE name = NewRow.battle) ALL (SELECT COUNT(*) FROM StarIn s, MovieStar mWHERE s.starName = m.nameGROUP BY s.movieTitle, m.gendar) )INSERT INTO MovieStar(SELECT * FROM OldStuff);* only considering DELETE from MovieStar since the assumption was thedesired condistion was satisfied before any change.* not considering INSERT into StarsIn since no gender info can beextracted from a new row for StarsIn.d)CREATE TRIGGER numMoviesTriggerAFTER INSERTINSERT ON MoviesREFERENCINGNEW TABLE AS NewStuffFOR EACH STATEMENTWHEN (100 ALL(SELECT COUNT(*) FROM MoviesGROUP BY studioName, year)DELETE FROM MoviesWHERE (title, year, length, genre, StudioName, procedureC#)IN NewStuff;CREATE TRIGGER numMoviesTrigger2AFTER UPDATEUPDATE ON MoviesREFERENCINGOLD TABLE AS OldStuffNEW TABLE AS NewStuffFOR EACH STATEMENTWHEN (100 ALL(SELECT COUNT(*) FROM MoviesGROUP BY studioName, year)BEGINDELETE FROM MoviesWHERE (title, year, length, genre, StudioName, procedureC#)IN NewStuff;INSERT INTO Movies (SELECT * FROM OldStuff);END;e)CREATE TRIGGER avgMovieLenTriggerAFTER INSERTINSERT ON MoviesREFERENCINGNEW TABLE AS NewStuffFOR EACH STATEMENTWHEN (120 ALL(SELECT AVG(length) FROM MoviesGROUP BY year)DELETE FROM MoviesWHERE (title, year, length, genre, StudioName, procedureC#)IN NewStuff;CREATE TRIGGER avgMovieLenTrigger2AFTER UPDATEUPDATE ON MoviesREFERENCINGOLD TABLE AS OldStuffNEW TABLE AS NewStuffFOR EACH STATEMENTWHEN (120 ALL(SELECT AVG(length) FROM MoviesGROUP BY year)BEGINDELETE FROM MoviesWHERE (title, year, length, genre, StudioName, procedureC#)IN NewStuff;INSERT INTO Movies (SELECT * FROM OldStuff);END;

    注意事项

    本文(数据库系统基础教程第七章答案.pdf)为本站会员(赵**)主动上传,淘文阁 - 分享文档赚钱的网站仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。 若此文所含内容侵犯了您的版权或隐私,请立即通知淘文阁 - 分享文档赚钱的网站(点击联系客服),我们立即给予删除!

    温馨提示:如果因为网速或其他原因下载失败请重新下载,重复下载不扣分。




    关于淘文阁 - 版权申诉 - 用户使用规则 - 积分规则 - 联系我们

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

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

    收起
    展开