数据库系统基础教程第二章答案终审稿Word文档下载推荐.docx
《数据库系统基础教程第二章答案终审稿Word文档下载推荐.docx》由会员分享,可在线阅读,更多相关《数据库系统基础教程第二章答案终审稿Word文档下载推荐.docx(17页珍藏版)》请在冰豆网上搜索。
type,
balance
)
Customers(
firstName,
lastName,
idNo,
account
Asuitabledomainforeachattribute:
acctNoInteger
typeString
balanceInteger
firstNameString
lastNameString
idNoString(becausethereisahyphenwecannotuseInteger)
accountInteger
AnotherequivalentwaytopresenttheAccountrelation:
acctNo
balance
type
34567
25
savings
23456
1000
checking
12345
12000
AnotherequivalentwaytopresenttheCustomersrelation:
idNo
firstName
lastName
account
805-333
Lena
Hand
901-222
Robbie
Banks
Exercise2.2.2
Examplesofattributesthatarecreatedforprimarilyservingaskeysinarelation:
UniversalProductCode(UPC)usedwidelyinUnitedStatesandCanadatotrackproductsinstores.
SerialNumbersonawidevarietyofproductstoallowthemanufacturertoindividuallytrackeachproduct.
VehicleIdentificationNumbers(VIN),auniqueserialnumberusedbytheautomotiveindustrytoidentifyvehicles.
Wecanorderthethreetuplesinanyof3!
=6ways.Also,thecolumnscanbeorderedinanyof3!
=6ways.Thus,thenumberofpresentationsis6*6=36.
Wecanorderthethreetuplesinanyof5!
=120ways.Also,thecolumnscanbeorderedinanyof4!
=24ways.Thus,thenumberofpresentationsis120*24=2880
Wecanorderthethreetuplesinanyofm!
ways.Also,thecolumnscanbeorderedinanyofn!
ways.Thus,thenumberofpresentationsisn!
m!
CREATETABLEProduct(
makerCHAR(30),
modelCHAR(10)PRIMARYKEY,
typeCHAR(15)
);
CREATETABLEPC(
modelCHAR(30),
speedDECIMAL(4,2),
ramINTEGER,
hdINTEGER,
priceDECIMAL(7,2)
CREATETABLELaptop(
screenDECIMAL(3,1),
CREATETABLEPrinter(
colorBOOLEAN,
typeCHAR(10),
ALTERTABLEPrinterDROPcolor;
ALTERTABLELaptopADDodCHAR(10)DEFAULT‘none’;
CREATETABLEClasses(
classCHAR(20),
typeCHAR(5),
countryCHAR(20),
numGunsINTEGER,
boreDECIMAL(3,1),
displacementINTEGER
CREATETABLEShips(
nameCHAR(30),
launchedINTEGER
CREATETABLEBattles(
dateDATE
CREATETABLEOutcomes(
shipCHAR(30),
battleCHAR(30),
resultCHAR(10)
ALTERTABLEClassesDROPbore;
ALTERTABLEShipsADDyardCHAR(30);
R1:
=σspeed≥3.00(PC)
R2:
=πmodel(R1)
model
1005
1006
1013
=σhd≥100(Laptop)
=Product
(R1)
R3:
=πmaker(R2)
maker
E
A
B
F
G
=σmaker=B(Product
PC)
Laptop)
Printer)
R4:
=πmodel,price(R1)
R5:
=πmodel,price(R2)
R6:
=πmodel,price(R3)
R7:
=R4
R5
R6
price
1004
649
630
1049
2007
1429
=σcolor=trueANDtype=laser(Printer)
=πmodel(R1)
3003
3007
=σtype=laptop(Product)
=σtype=PC(Product)
=πmaker(R1)
=πmaker(R2)
=R3–R4
=ρPC1(PC)
R2:
=ρPC2(PC)
R3:
=R1
(PC1.hd=PC2.hdANDPC1.model<
>
PC2.model)R2
R4:
=πhd(R3)
hd
250
80
160
(PC1.speed=PC2.speedANDPC1.ram=PC2.ramANDPC1.model<
=πPC1.model,PC2.model(R3)
PC1.model
PC2.model
1012
=πmodel(σspeed≥2.80(PC))
πmodel(σspeed≥2.80(Laptop))
=πmaker,model(R1
Product)
=ρR3(maker2,model2)(R2)
=R2
(maker=maker2ANDmodel<
model2)R3
=πmaker(R4)
=πmodel,speed(PC)
=πmodel,speed(Laptop)
R2
=ρR4(model2,speed2)(R3)
=πmodel,speed(R3
(speed<
speed2)R4)
R6:
=R3–R5
=πmaker(R6
=πmaker,speed(Product
=ρR2(maker2,speed2)(R1)
=ρR3(maker3,speed3)(R1)
(maker=maker2ANDspeed<
speed2)R2
(maker3=makerANDspeed3<
speed2ANDspeed3<
speed)R3
=πmaker(R5)
D
=πmaker,model(Product
=ρR2(maker2,model2)(R1)
=ρR3(maker3,model3)(R1)
=ρR4(maker4,model4)(R1)
R5:
model2)R2
R6:
=R3
(maker3=makerANDmodel3<
model2ANDmodel3<
model)R5
R7:
(maker4=makerAND(model4=modelORmodel4=model2ORmodel4=model3))R6
R8:
=πmaker(R7)
=σbore≥16(Classes)
=πclass,country(R1)
class
country
Iowa
USA
NorthCarolina
Yamato
Japan
=σlaunched<
1921(Ships)
=πname(R1)
name
Haruna
Hiei
Kirishima
Kongo
Ramillies
Renown
Repulse
Resolution
Revenge
RoyalOak
RoyalSovereign
Tennessee
=σbattle=DenmarkStraitANDresult=sunk(Outcomes)
=πship(R1)
ship
Bismarck
Hood
=Classes
Ships
=σlaunched>
1921ANDdisplacement>
35000(R1)
=πname(R2)
Missouri
Musashi
NewJersey
Washington
Wisconsin
=σbattle=Guadalcanal(Outcomes)
=Ships
(ship=name)R1
=πname,displacement,numGuns(R3)
displacement
numGuns
32000
8
37000
9
=πname(Ships)
=πship(Outcomes)
=ρR3(name)(R2)
R3
California
Arizona
DukeofYork
Fuso
KingGeorgeV
PrinceofWales
Rodney
Scharnhorst
SouthDakota
WestVirginia
Yamashiro
From2.3.2,assumingthateveryclasshasoneshipnamedaftertheclass.
=πclass(Classes)
=πclass(σname<
class(Ships))
=R1–R2
=πcountry(σtype=bb(Classes))
=πcountry(σtype=bc(Classes))
=R1∩R2
Gt.Britain
=πship,result,date(Battles
(battle=name)Outcomes)
=ρR2(ship2,result2,date2)(R1)
(ship=ship2ANDresult=damagedANDdate<
date2)R2
=πship(R3)
Noresultsfromsampledata.
Exercise2.4.5
Theresultofthenaturaljoinhasonlyoneattributefromeachpairofequatedattributes.Ontheotherhand,theresultofthetheta-joinhasbothcolumnsoftheattributesandtheirvaluesareidentical.
Exercise2.4.6
Union
Ifweaddatupletotheargumentsoftheunionoperator,wewillgetallofthetuplesoftheoriginalresultandmaybetheaddedtuple.Iftheaddedtupleisaduplicatetuple,thenthesetbehaviorwilleliminatethattuple.Thustheunionoperatorismonotone.
Intersection
Ifweaddatupletotheargumentsoftheintersectionoperator,wewillgetallofthetuplesoftheoriginalresultandmaybetheaddedtuple.Iftheaddedtupledoesnotexistintherelationthatitisaddedbutdoesexistintheotherrelation,thentheresultsetwillincludetheaddedtuple.Thustheintersectionoperatorismonotone.
Difference
Ifweaddatupletotheargumentsofthedifferenceoperator,wemaynotgetallofthetuplesoftheoriginalresult.SupposewehaverelationsRandSandwearecomputingR–S.SupposealsothattupletisinRbutnotinS.TheresultofR–Swouldincludetuplet.However,ifweaddtuplettoS,thenthenewresultwillnothavetuplet.Thusthedifferenceoperatorisnotmonotone.
Projection
Ifweaddatupletotheargumentsoftheprojectionoperator,wewillgetallofthetuplesoftheoriginalresultandtheprojectionoftheaddedtuple.Theprojectionoperatoronlyselectscolumnsfromtherelationanddoesnotaffecttherowsthatareselected.Thustheprojectionoperatorismonotone.
Selection
Ifweaddatupletotheargumentsoftheselectionoperator,wewillgetallofthetuplesoftheoriginalresultandmaybetheaddedtuple.Iftheaddedtuplesatisfiestheselectcondition,thenitwillbeaddedtothenewresult.Theoriginaltuplesareincludedinthenewresultbecausetheystillsatisfytheselectcondition.Thustheselectionoperatorismonotone.
CartesianProduct
IfweaddatupletotheargumentsoftheCartesianproductoperator,wewillgetallofthetuplesoftheoriginalresultandpossiblyadditionaltuples.TheCartesianproductpairsthetuplesofonerelationwiththetuplesofanotherrelation.SupposethatwearecalculatingRxSwhereRhasmtuplesandShasntuples.IfweaddatupletoRthatisnotalreadyinR,thenweexpecttheresultofRxStohave(m+1)*ntuples.ThustheCartesianproductoperatorismonotone.
NaturalJoins
Ifweaddatupletotheargumentsofanaturaljoinoperator,wewillgetallofthetuplesoftheoriginalresultandpossiblyadditionaltuples.Thenewtuplecanonlycreateadditionalsuccessfuljoins,notless.If,however,the