数据库系统基础教程第二章答案 下载本文

内容发布更新时间 : 2024/5/4 1:53:46星期一 下面是文章的全部内容请认真阅读。

数据库系统基础教程第

二章答案

集团标准化工作小组 #Q8QGGQT-GX8G08Q8-GNQGJ8-MHHGN#

For relation Accounts, the attributes are:

acctNo, type, balance

For relation Customers, the attributes are: firstName, lastName, idNo, account For relation Accounts, the tuples are: (12345, savings, 12000), (23456, checking, 1000), (34567, savings, 25)

For relation Customers, the tuples are: (Robbie, Banks, 901-222, 12345), (Lena, Hand, 805-333, 12345), (Lena, Hand, 805-333, 23456)

For relation Accounts and the first tuple, the components are: 123456 acctNo savings type 12000 balance

For relation Customers and the first tuple, the components are: Robbie firstName Banks lastName 901-222 idNo 12345 account

For relation Accounts, a relation schema is: Accounts(acctNo, type, balance) For relation Customers, a relation schema is: Customers(firstName, lastName, idNo, account) An example database schema is: Accounts ( acctNo, type, balance )

Customers ( firstName, lastName, idNo, account )

A suitable domain for each attribute: acctNo Integer type String balance Integer firstName String lastName String idNo String (because there is a hyphen we cannot use Integer) account Integer

Another equivalent way to present the Account relation: acctNo balance type 34567 25 savings 23456 1000 checking 12345 12000 savings Another equivalent way to present the Customers relation: idNo firstName lastName account 805-333 Lena Hand 23456 805-333 Lena Hand 12345 901-222 Robbie Banks 12345 Exercise of attributes that are created for primarily serving as keys in a relation: Universal Product Code (UPC) used widely in United States and Canada to track products in stores.

Serial Numbers on a wide variety of products to allow the manufacturer to individually track each product.

Vehicle Identification Numbers (VIN), a unique serial number used by the automotive industry to identify vehicles.

We can order the three tuples in any of 3! = 6 ways. Also, the columns can be ordered in any of 3! = 6 ways. Thus, the number of presentations is 6*6 = 36.

We can order the three tuples in any of 5! = 120 ways. Also, the columns can be ordered in any of 4! = 24 ways. Thus, the number of presentations is 120*24 = 2880

We can order the three tuples in any of m! ways. Also, the columns can be ordered in any of n! ways. Thus, the number of presentations is n!m! CREATE TABLE Product ( maker CHAR(30), model CHAR(10) PRIMARY KEY, type CHAR(15) );

CREATE TABLE PC ( model CHAR(30), speed DECIMAL(4,2), ram INTEGER, hd INTEGER, price DECIMAL(7,2) );

CREATE TABLE Laptop ( model CHAR(30), speed DECIMAL(4,2), ram INTEGER,

hd INTEGER, screen DECIMAL(3,1), price DECIMAL(7,2) );

CREATE TABLE Printer ( model CHAR(30), color BOOLEAN, type CHAR (10), price DECIMAL(7,2) );

ALTER TABLE Printer DROP color;

ALTER TABLE Laptop ADD od CHAR (10) DEFAULT ‘none’; CREATE TABLE Classes ( class CHAR(20), type CHAR(5), country CHAR(20), numGuns INTEGER, bore DECIMAL(3,1), displacement INTEGER );

CREATE TABLE Ships ( name CHAR(30), class CHAR(20), launched INTEGER );

CREATE TABLE Battles ( name CHAR(30), date DATE );

CREATE TABLE Outcomes ( ship CHAR(30), battle CHAR(30), result CHAR(10) );

ALTER TABLE Classes DROP bore;

ALTER TABLE Ships ADD yard CHAR(30); R1 := σspeed ≥ (PC)

R2 := πmodel(R1)

R1 := σhd ≥ 100 (Laptop) R2 := Product (R1) model R3 := π (R2) maker1005 R1 := σmaker=B (Product PC) 1006 maker R2 := σmaker=B (Product Laptop) 1013 E R3 := σmaker=B (Product Printer) A R4 := πmodel,price (R1)

R5 := πmodel,price (R2) B R6: = πmodel,price (R3) F G R7 := R4 R5 R6 model price 1004 649 1005 630 1006 1049 2007 1429 R1 := σcolor = true AND type = laser (Printer) R2 := πmodel (R1)

model R1 := σtype=laptop (Product) 3003 R2 := σtype=PC(Product) 3007 R3 := πmaker(R1) R4 := πmaker(R2) R5 := R3 – R4

R1 := ρPC1(PC) R2 := ρPC2(PC) maker R3 := R1 = AND <> R2 F R4 := π(R3) hdG R1 := ρPC1(PC) hd R2 := ρPC2(PC) 250 R3 := R1 = AND = AND < R2 80 R4 := π,(R3) 160 R1 := πmodel(σspeed ≥ (PC)) πmodel(σspeed ≥ (Laptop))

1004 1012 R2 := πmaker,model(R1 Product)

R3 := ρR3(maker2,model2)(R2) R4 := R2 (maker = maker2 AND model <> model2) R3 R5 := πmaker(R4)

R1 := πmodel,speed(PC)

maker R2 := πmodel,speed(Laptop)

B R3 := R1 R2 E R4 := ρR4(model2,speed2)(R3)

R5 := πmodel,speed (R3 (speed < speed2 ) R4) R6 := R3 – R5

R7 := πmaker(R6 Product) maker B R1 := πmaker,speed(Product PC) R2 := ρR2(maker2,speed2)(R1) R3 := ρR3(maker3,speed3)(R1) R4 := R1 (maker = maker2 AND speed <> speed2) R2 R5 := R4 (maker3 = maker AND speed3 <> speed2 AND speed3 <> speed) R3 R6 := πmaker(R5)

R1 := πmaker,model(Product PC)

maker R2 := ρR2(maker2,model2)(R1) A R3 := ρR3(maker3,model3)(R1) D R4 := ρR4(maker4,model4)(R1) E R5 := R1 (maker = maker2 AND model <> model2) R2 R6 := R3 (maker3 = maker AND model3 <> model2 AND model3 <> model) R5 R7 := R4 (maker4 = maker AND (model4=model OR model4=model2 OR model4=model3)) R6 R8 := πmaker(R7)

R1 := σbore ≥ 16 (Classes) maker R2 := πclass,country (R1) A B D E class country Iowa USA North Carolina USA Yamato Japan R1 := σlaunched < 1921 (Ships) R2 := πname (R1) name Haruna Hiei Kirishima Kongo Ramillies Renown Repulse Resolution Revenge Royal Oak Royal Sovereign Tennessee R1 := σbattle=Denmark Strait AND result=sunk(Outcomes) R2 := πship (R1) ship Bismarck Hood R1 := Classes Ships R2 := σlaunched > 1921 AND displacement > 35000 (R1) R3 := πname (R2) name Iowa Missouri Musashi New Jersey North Carolina Washington Wisconsin Yamato R1 := σbattle=Guadalcanal(Outcomes) R2 := Ships (ship=name) R1 R3 := Classes R2

R4 := πname,displacement,numGuns(R3) name displacement numGuns Kirishima 32000 8 Washington 37000 9 R1 := πname(Ships) R2 := πship(Outcomes) R3 := ρR3(name)(R2) R4 := R1

R3

name California Haruna Hiei Iowa Kirishima Kongo

Missouri Musashi New Jersey North Carolina Ramillies class Renown Bismarck Repulse Resolution country Revenge Japan Royal Oak Gt. Britain Royal Sovereign Tennessee Washington Wisconsin Yamato Arizona Bismarck Duke of York Fuso Hood King George V Prince of Wales Rodney Scharnhorst South Dakota West Virginia Yamashiro From assuming that every class has one ship named after the class. R1 := πclass(Classes) R2 := πclass(σname <> class(Ships)) R3 := R1 – R2 R1 := πcountry(σtype=bb(Classes)) R2 := πcountry(σtype=bc(Classes)) R3 := R1 ∩ R2 R1 := πship,result,date(Battles (battle=name) Outcomes) R2 := ρR2(ship2,result2,date2)(R1) R3 := R1 (ship=ship2 AND result=damaged AND date < date2) R2 R4 := πship(R3) No results from sample data.

result of the natural join has only one attribute from each pair of equated attributes. On the other result of the theta-join has both columns of the attributes and their values are identical.

Exercise we add a tuple to the arguments of the union operator, we will get all of the tuples of the original result and maybe the added tuple. If the added tuple is a duplicate tuple, then the set behavior will eliminate that tuple. Thus the union operator is monotone. Intersection

If we add a tuple to the arguments of the intersection operator, we will get all of the tuples of the original result and maybe the added tuple. If the added tuple does not exist in the relation that it is added but does exist in the other relation, then the result set will include the added tuple. Thus the intersection operator is monotone.

If we add a tuple to the arguments of the difference operator, we may not get all of the tuples of the original result. Suppose we have relations R and S and we are computing R – S. Suppose also that tuple t is in R but not in S. The result of R – S would include tuple t. However, if we add tuple t to S, then the new result will not have tuple t. Thus the difference operator is not monotone.

Exercise hand, the

Difference

Projection

If we add a tuple to the arguments of the projection operator, we will get all of the tuples of the

original result and the projection of the added tuple. The projection operator only selects columns from the relation and does not affect the rows that are selected. Thus the projection operator is monotone.

Selection

If we add a tuple to the arguments of the selection operator, we will get all of the tuples of the original result and maybe the added tuple. If the added tuple satisfies the select condition, then it will be added to the new result. The original tuples are included in the new result because they still satisfy the select condition. Thus the selection operator is monotone.

Cartesian Product

If we add a tuple to the arguments of the Cartesian product operator, we will get all of the tuples of the original result and possibly additional tuples. The Cartesian product pairs the tuples of one relation with the tuples of another relation. Suppose that we are calculating R x S where R has m tuples and S has n tuples. If we add a tuple to R that is not already in R, then we expect the result of R x S to have (m + 1) * n tuples. Thus the Cartesian product operator is monotone.

Natural Joins

If we add a tuple to the arguments of a natural join operator, we will get all of the tuples of the original result and possibly additional tuples. The new tuple can only create additional successful joins, not less. If, however, the added tuple cannot successfully join with any of the existing tuples, then we will have zero additional successful joins. Thus the natural join operator is monotone.

Theta Joins

If we add a tuple to the arguments of a theta join operator, we will get all of the tuples of the original result and possibly additional tuples. The theta join can be modeled by a Cartesian product followed by a selection on some condition. The new tuple can only create additional tuples in the result, not less. If, however, the added tuple does not satisfy the select condition, then no additional tuples will be added to the result. Thus the theta join operator is monotone.

Renaming

If we add a tuple to the arguments of a renaming operator, we will get all of the tuples of the original result and the added tuple. The

renaming operator does not have any effect on whether a tuple is selected or not. In fact, the renaming operator will always return as many tuples as its argument. Thus the renaming operator is monotone.

If all the tuples of R and S are different, then the union has n + m tuples, and this number is the maximum possible.

The minimum number of tuples that can appear in the result occurs if every tuple of one relation also appears in the other. Then the union has max(m , n) tuples.

If all the tuples in one relation can pair successfully with all the tuples in the other relation, then the natural join has n * m tuples. This number would be the maximum possible.

The minimum number of tuples that can appear in the result occurs if none of the tuples of one relation can pair successfully with all the tuples in the other relation. Then the natural join has zero tuples.

If the condition C brings back all the tuples of R, then the cross product will contain n * m tuples. This number would be the maximum possible. The minimum number of tuples that can appear in the result occurs if the condition C brings back none of the tuples of R. Then the cross product has zero tuples.

Assuming that the list of attributes L makes the resulting relation πL(R) and relation S schema compatible, then the maximum possible tuples is n. This happens when all of the tuples of πL(R) are not in S.

The minimum number of tuples that can appear in the result occurs when all of the tuples in πL(R) appear in S. Then the difference has max(n – m , 0) tuples.

Exercise r as the schema of R and s as the schema of S:

1. πr(R S) 2. 3. R δ(πr∩s(S)) where δ is the duplicate-elimination operator in Section pg. 213 4.

5. R – (R – πr(R S)) Exercise r as the schema of R

1. R - πr(R S) πA1,A2…An(R S)

σspeed < AND price > 500(PC) =