数据库系统基础教程第七章答案.docx
《数据库系统基础教程第七章答案.docx》由会员分享,可在线阅读,更多相关《数据库系统基础教程第七章答案.docx(17页珍藏版)》请在淘文阁 - 分享文档赚钱的网站上搜索。
1、SolutionsChapter 77.1.1a)CREATE TABLE Movies (title year length genre studioName producerC#CHAR(100), INT, INT, CHAR(10), CHAR(30), INT,PRIMARY KEY (title, year),FOREIGN KEY (producerC#) REFERENCES MovieExec(cert#) );orCREATE TABLE Movies (title year length genre studioName producerC#CHAR(100),INT,I
2、NT,CHAR(10),CHAR(30),INTREFERENCES MovieExec(cert#),PRIMARY KEY (title, year) );b)CREATE TABLE Movies (titleyear length genre studioName producerC#CHAR(100),INT,INT,CHAR(10),CHAR(30), INTREFERENCES MovieExec(cert#)ON DELETE SET NULL ON UPDATE SET NULL, PRIMARY KEY (title, year) );c)CREATE TABLE Movi
3、es (title year lengthCHAR(100), INT, INT,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,
4、movieYear, starName) );e)CREATE TABLE StarsIn (movieTitleCHAR(100)REFERENCES Movie(title)ON DELETE CASCADE,movieYearINT,starNameCHAR(30),PRIMARY KEY (movieTItle, movieYear, starName);7.1.2To declare such a foreign-key constraint between the relations Movie and StarsIn, values of the referencing attr
5、ibutes in Movie should appear in MovieStar as unique values. However, based on primary key declaration in relation StarIn, the uniqueness of movies is guaranteed with movieTitle, movieYear, and starName attributes.Even with titleand year as referencing attributes there is no way of referencing uniqu
6、e movie from StarsIn without starName information. Therefore, such a constraint can not be expressed using a foreign-key constraint.7.1.3ALTER TABLE ProductADD PRIMARY KEY (model);ALTER TABLE PCADD FOREIGN KEY (model) REFERENCES Product (model);ALTER TABLE LaptopADD FOREIGN KEY (model) REFERENCES Pr
7、oduct(model);ALTER TABLE PrinterADD FOREIGN KEY (model)REFERENCES Product (model);ALTER 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 F
8、OREIGN 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 the primary k
9、ey 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;a)yearINTCHECK (year = 1915)b)lengthINTCHECK (length= 60 AND length
10、=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 (7.2.1?) )modelCHAR(4)CHECK (model IN (SELECT model FROM PCUNION ALLSELECT model FROM laptopUNION A
11、LLSELECT model FROM printer);* note this doesn?t check the attribute constraint violation caused bydeletions from PC, laptop, or printer7.2.3a)CREATE TABLE StarsIn (starName CHAR(30)CHECK (starName IN (SELECT name FROM MovieStarWHERE YEAR(birthdate) movieYear);b)CREATE TABLE Studio (address CHAR(255
12、);CHECK (address IS UNIQUE)c)CREATE TABLE MovieStar (name CHAR(30);d)CREATE TABLE Studio (Name CHAR(30);e)CREATE TABLE Movies (CHECK (name NOT IN (SELECT name FROM MovieExec)CHECK (name IN (SELECT studioName FROM Movies)CHECK (producerC# NOT IN (SELECT presC# FROM Studio) ORstudioName IN (SELECT nam
13、e FROM StudioWHERE presC# = producerC#);7.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 oWHERE s.name = o.ship ANDb.name = o.battle ANDs.launch
14、ed 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.1a)ALTER TABLE Movie ADD CONSTRAINT myKey PRIMARY KEY (title, year);b)ALTER TABLE Movie ADD CONSTRAINT producerCheck FOREIGN KEY (producerC#) REFERENCES MovieExec
15、 (cert#);c)ALTER TABLE Movie ADD CONSTRAINT lengthCheck CHECK (length = 60 AND length 14);e)ALTER TABLE Ships ADD CONSTRAINT shipDateCheckCHECK (ship IN (SELECT s.name FROM Ships s, Battles b, Outcomes oWHERE s.name = o.ship ANDb.name = o.battle ANDs.launched = YEAR(b.date)7.4.1a)CREATE ASSERTION CH
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 数据库 系统 基础教程 第七 答案
限制150内