0% found this document useful (0 votes)
8 views

Database 3

Uploaded by

tadele766
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views

Database 3

Uploaded by

tadele766
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 18

Fundament

also
fDat
abas
e Sys
tems Chapt
erI
I

Chapt
erTwo
TheRe
lat
ionalDat
abas
eMo
del
Chapt
erc
ont
ent
:
 Hi
sto
ryo
fther
elat
ionalMo
del
 Re
lat
ionalMo
delTe
rmi
nol
ogy
 Mat
hemat
icalDe
fini
ti
ono
fRe
lat
ion
 Dat
abas
eRe
lat
ions
 Re
lat
ionalKe
ys
 Re
lat
ionalI
nte
gri
ty
 Re
lat
ionalDat
abas
eop
erat
or
 Vi
ew
 Re
lat
ionalAl
gebr
a
 Re
lat
ionalAl
gebr
aOp
erat
ors
 Re
lat
ionalCal
cul
usatGl
anc
e

Hi
sto
ryo
ftheRel
ati
onalMo
del
 Re
lat
ionalDat
abas
eMo
delhi
sto
ry
– Pr
opo
sedbyCo
ddi
n19
70
– Pi
one
erp
roj
ect
ssu
chasatI
BMandUC-Be
rke
leyi
nmi
d-1
970
s
– To
day,
sti
llt
hedo
minantdat
abas
emo
del
:
• I
BMDB2
,ORACLE,
INFORMI
X,SYBASE
• MI
CROSOFTAc
ces
s,SQLSe
rve
r
• FOXBASE,
PARADOX
 Ther
elat
ionalmo
del
pro
vide
sal
ogi
cal
rep
res
ent
ati
ono
fthedat
a
Rel
ati
onalMo
delTer
mino
logy
 Ar
elat
ioni
sat
abl
ewi
thc
olu
mnsandr
ows
.
– Onl
yap
pli
est
olo
gic
als
tru
ctu
reo
fthedat
abas
e,no
tthep
hys
icals
tru
ctu
re.
– Ar
elat
ionc
orr
esp
ondst
oane
nti
tys
et,o
rco
ll
ect
iono
fent
iti
es.Ane
nti
tyi
sap
ers
on,p
lac
e,
e
vent
,ort
hingabo
utwhi
chda
tai
sco
ll
ect
ed
 At
tri
but
eisaname
dco
lumno
far
ela
tio
n.I
tco
rre
spo
ndst
oac
har
act
eri
sti
cofane
nti
ty.
– The
yar
eal
soc
all
edfi
el
ds.
 Do
mai
nist
hes
eto
fal
lo
wabl
eval
uesfo
roneo
rmo
reat
tri
but
es.
 Tupl
eisar
owo
far
elat
ion.
 Degr
eei
sthenu
mbe
rofat
tri
but
esi
nar
elat
ion.
 Car
dinal
it
yist
henu
mbe
roft
upl
esi
nar
elat
ion
.
 Re
lat
ionalDat
abas
eisac
oll
ect
iono
fno
rmal
iz
edr
elat
ionswi
thdi
sti
nctr
elat
ionname
s.

St
.Mar
y’sUni
ver
sit
y 1
5
Fundament
also
fDat
abas
e Sys
tems Chapt
erI
I

 NBar
elat
ioni tanERD(
sno Ent
ityRe
lat
ions
hipDi
agr
am)r
elat
ions
hip
,bu
tane
nti
tys
et.
I
nst
anc
eso
fBr
anc
handSt
aff(
par
t)Rel
ati
ons

Ex
ampl
eso
fAt
tri
but
eDo
mai
ns

Al
ter
nat
iveTer
mino
logyfo
rRel
ati
onalMo
del

Mat
hemat
icalDefi
nit
iono
fRel
ati
on
Co
nsi
dert
wos
ets
,D1&D2,
whe
reD1={
2,}andD2={
4 1,3
,5}
.
Car
tes
ianp
rodu
ct,D1 XD2,i
sse
tofal
lor
der
edp
air
s,whe
refi
rste
leme
nti
sme
mbe
rofD1 ands
eco
nd
e
leme
nti
sme
mbe
rofD2.
D1XD2={
(2,
1),
(2,
3),
(2,
5),
(4,
1),
(4,
3),
(4,
5)}
Al
ter
nat
ivewayi
stofi
ndal
lco
mbi
nat
ion
sofe
leme
ntswi
thfi
rstfr
omD1ands
eco
ndfr
omD2.
Anys
ubs
eto
fCar
tes
ianp
rodu
cti
sar
elat
ion;e
.g.
R={(
2,1
),(
4,1
)}

St
.Mar
y’sUni
ver
sit
y 1
6
Fundament
also
fDat
abas
e Sys
tems Chapt
erI
I

 Mays
pec
ifywhi
chp
air
sar
einr
elat
ionu
sings
omec
ondi
ti
onfo
rse
lec
tio
n;e
.g.
– s
eco
nde
leme
nti
s1:
R={(
x,y)|xεD1,
yεD2,
andy=1
}
– fi
rste
leme
nti
sal
wayst
wic
ethes
eco
nd:
S={(
x,y)|xεD1,
yεD2,
andx=2
y}
 Co
nsi
dert
hre
ese
tsD1,
D2,
D3wi
thCar
tes
ianPr
odu
ctD1XD2XD3;e
.g.
D1={
1,3
} D2={
2,4
} D3={
5,6
}
D1xD2xD3={
(1,
2,
5),
(1,
2,
6),
(1,
4,
5),
(1,
4,
6),
(3,
2,
5),
(3,
2,
6),
(3,
4,
5),
(3,
4,
6)}
– Anys
ubs
eto
fthe
seo
rde
redt
rip
lesi
sar
elat
ion.
 TheCar
tes
ianp
rodu
c fns
to et D1,
s( D2,
...
,Dn)i
s:
D1XD2X.
..XDn={
(d1,
d2,
...
,dn)|d1ε
D1,
d2ε
D2,
...
,dnε
Dn}us
ual
lywr
itt
enas
:
n
XDi
i=1
 Anysetofn-t
upl
esfr
omt
hisCar
tes
ianp
rodu
cti
sar
elat
iono
nthens
ets
.
Dat
abas
eRel
ati
ons
 Rel
ati
ons
chema
– Name
dre
lat
ionde
fine
dbyas
eto
fat
tri
but
eanddo
mai
nnamep
air
s.
 Rel
ati
onaldat
abas
esc
hema
– Se
tofr
elat
ions
che
mas
,eac
hwi
thadi
sti
nctname
.
Pr
oper
tieso
fRel
ati
ons
 Re
lat
ionnamei
sdi
sti
nctfr
omal
lot
herr
elat
ionname
sinr
elat
ionals
che
ma.
 Eac
hce
llo
fre
lat
ionc
ont
ainse
xac
tlyo
neat
omi
c(s
ingl
e)v
alu
e.
 Eac
hat
tri
but
ehasadi
sti
nctname
.
 Val
ueso
fanat
tri
but
ear
eal
lfr
omt
hes
amedo
mai
n.
 Eac
htu
plei
sdi
sti
nct
;the
rear
enodu
pli
cat
etu
ple
s.
 Or
dero
fat
tri
but
eshasnos
igni
fic
anc
e.
 Or
dero
ftu
ple
shasnos
igni
fic
anc
e,t
heo
ret
ical
ly.
Tabl
eChar
act
eri
sti
cs
 Eac
hRDBMShasi
tsr
ule
sfo
rtabl
ean
dco
lumnname
s.
Ex
amp
le:Mi
cro
softAc
ces
s
Tabl
ename
s<=6
4(8i
scl
ass
ical
)
Co
lumnname
s<=6
4(1
0isc
las
sic
al)
Co
lumnna
mesc
anno
tst
artwi
thdi
gito
rco
ntai
nsp
eci
alc
har
act
ers
e
xce
ptu
nde
rsc
oreandafe
wot
her
s
 Eac
hRDBMShasi
tsr
ule
sfo
ras
soc
iat
ingadat
atyp
etoanat
tri
but
e,bu
tthe
rear
ecl
ass
icalo
nes
:tex
t,
c
har
act
er,
number
,dat
e,Bo
olean

St
.Mar
y’sUni
ver
sit
y 1
7
Fundament
also
fDat
abas
e Sys
tems Chapt
erI
I

Rel
ati
onalKeys
 Ke
y
 Oneo
rmo
reat
tri
but
est
hatde
ter
min
eot
herat
tri
but
es
 Ke
yat
tri
but
e
 Co
mpo
sit
eke
y
 The
rene
edst
obefu
llfu
nct
ionalde
pende
ncefr
omk
eyt
oanyo
the
rat
tri
but
e
 Ke
ysmaybe
 Si
ngl
e
 Co
mpo
sit
e(c
omp
ose
dofs
eve
ralk
eyat
tri
but
es)
 Ex
amp
le:s
taff_fName
,st
aff_l
Name
,st
aff_i
nit
,st
aff_p
hone s
taff_DOB,
staff_p
osi
ti
on
 Func
tio
naldependenc
e:at
tri
but
eA2i
sfu
nct
ional
lyde
pende
nto
nac
omp
osi
tek
eyA1,
butno
tonanys
ubs
et
o
fit
 Func
tio
naldependenc
e:anat
tri
but
eAi
sfu
nct
iona
ll
yde
pende
nto
nanat
tri
but
eKi
seac
hval
uei
nco
lumnK
de
ter
mine
soneando
nlyo
nev
alu
einc
olu
mnA.
K A(
Kde
ter
mine
sA)
.
 At
tri
but
eKde
ter
mine
sat
tri
but
eAi
fal
lro
wsi
nthet
abl
ethatagr
eei
nval
uefo
rat
tri
but
eKmu
stal
so
agr
eei
nval
uefo
rat
tri
but
eA.
 At
tri
but
eAi
sfu
nct
ional
lyde
pende
nto
nKi
fKde
ter
mine
sA.
Keys
 Super
key
 Anat
tri
but
e,o
ras
eto
fat
tri
but
es,
thatu
niqu
elyi
dent
ifi
esat
upl
ewi
thi
nar
elat
ion.
 Candi
dat
eKey
 Su
per
key(
K)s
ucht
hatnop
rop
ers
ubs
eti
sas
upe
rke
ywi
thi
nther
elat
ion.
 I
neac
htu
pleo
fR,
val
ueso
fKu
niqu
elyi
den
tifyt
hatt
upl
e(u
niqu
ene
ss)
.
 Nop
rop
ers
ubs
eto
fKhast
heu
niqu
ene
ssp
rop
ert
y(i
rre
duc
ibi
li
ty)
.

St
.Mar
y’sUni
ver
sit
y 1
8
Fundament
also
fDat
abas
e Sys
tems Chapt
erI
I

 Pr
imar
yKey
 Candi
dat
eke
yse
lec
tedt
oide
nti
fyt
upl
esu
niqu
elywi
thi
nre
lat
ion.
 Al
ter
nat
eKeys
 Candi
dat
eke
yst
hatar
eno
tse
lec
tedt
obep
rimar
yke
y.
 Fo
rei
gnKey
 At
tri
but
e,o
rse
tofat
tri
but
es,
wit
hino
ner
elat
iont
hatmat
che
scandi
dat
eke
yofs
ome(
pos
sibl
y
s
ame
)re
lat
ion.
Rel
ati
onalI
ntegr
ity
 Nul
l
 Re
pre
sent
sval
uefo
ranat
tri
but
ethati
scu
rre
ntl
yunk
nowno
rno
tap
pli
cabl
efo
rtu
ple
.
 De
alswi
thi
nco
mpl
eteo
rex
cep
tio
naldat
a.
 Re
pre
sent
stheabs
enc
eofav
alu
eandi
sno
tthes
ameasz
eroo
rsp
ace
s,whi
char
eval
ues
.
 Ent
ityI
ntegr
ity
 I
nabas
ere
lat
ion,
noat
tri
but
eofap
rimar
yke
ycanbenu
ll
.
 Ens
ure
sthatal
lent
iti
esar
euni
que
.
 Refer
ent
ialI
ntegr
ity
 I
ffo
rei
gnk
eye
xis
tsi
nar
elat
ion,
eit
herfo
rei
gnk
eyv
alu
emu
stmat
chac
andi
dat
eke
yval
ueo
f
s
omet
upl
eini
tsho
mer
elat
iono
rfo
rei
gnk
eyv
alu
emu
stbewho
ll
ynu
ll
.
 Ent
erpr
iseCo
nst
rai
nts
 Addi
ti
onalr
ule
ssp
eci
fie
dbyu
ser
sordat
abas
eadmi
nis
trat
ors
.
Rel
ati
onalDat
abas
eOper
ato
rs
 Re
lat
ionalal
gebr
ade
ter
mine
stabl
emani
pul
ati
ons
 Ke
yop
era
tor
s(mi
nimal
lyr
elat
ionalRDBMS)
 SELECT
 PROJ
ECT
 J
OIN
 Ot
hero
per
ato
rs
 I
NTERSECT
 UNI
ON(
uni
onc
omp
ati
blet
abl
es)
 DI
FFERENCE
 PRODUCT
 DI
VIDE

St
.Mar
y’sUni
ver
sit
y 1
9
Fundament
also
fDat
abas
e Sys
tems Chapt
erI
I

Uni
on
 Co
mbi
nesal
lro
ws

I
nter
sec
t
 Yi
el
dsr
owst
hatap
peari
nbo
tht
abl
es

Di
ffer
enc
e
 Yi
el
dsr
owsno
tfo
undi
not
hert
abl
es

St
.Mar
y’sUni
ver
sit
y 2
0
Fundament
also
fDat
abas
e Sys
tems Chapt
erI
I

Pr
oduc
t
 Yi
el
dsal
lpo
ssi
blep
air
sfr
omt
wot
abl
es

Sel
ect
 Yi
el
dsas
ubs
eto
fro
wsbas
edo
nsp
eci
fie
dcr
ite
rio
n

St
.Mar
y’sUni
ver
sit
y 2
1
Fundament
also
fDat
abas
e Sys
tems Chapt
erI
I

Pr
ojec
t
 Yi
el
dsal
lval
uesfo
rse
lec
tedat
tri
but
es

J
oin
 I
nfo
rmat
ionfr
omt
woo
rmo
ret
abl
esi
sco
mbi
ned

Nat
uralJ
oinPr
oce
ss
 Li
nkst
abl
esbys
ele
cti
ngr
owswi
thc
ommo
nval
uesi
nco
mmo
nat
tri
but
e(s
)
 Thr
ee-s
tagep
roc
ess
 Pr
odu
ctc
reat
eso
net
abl
e
 Se
lec
tyi
el
dsap
pro
pri
ater
ows
 Pr
oje
ctyi
el
dss
ingl
eco
pyo
feac
hat
tri
but
etoe
li
minat
edu
pli
cat
eco
lumns
 El
imi
nat
esdu
pli
cat
es

St
.Mar
y’sUni
ver
sit
y 2
2
Fundament
also
fDat
abas
e Sys
tems Chapt
erI
I

 Do
esno
tinc
luder
owst
hatar
eunmat
che
d
Ot
herJ
oins
 Equi
JOI
N
 Li
nkst
abl
esbas
edo
nequ
ali
tyc
ondi
ti
ont
hatc
omp
are
ssp
eci
fie
dco
lumnso
ftabl
es
 Do
esn
ote
li
minat
edu
pli
cat
eco
lumns
 J
oinc
rit
eri
amu
stbee
xpl
ic
itl
yde
fine
d
 Thet
aJOI
N
 Equ
iJOI
Nthatc
omp
are
ssp
eci
fie
dco
lumnso
feac
htabl
eus
ingo
per
ato
rot
hert
hane
qual
it
yone
 Out
erJ
OIN
 Mat
che
dpai
rsar
ere
tai
ned
 Unma
tche
dval
uesi
not
hert
abl
esl
eftnu
ll
 Ri
ghtandl
eft

Di
vi
de
 Re
qui
resu
sero
fsi
ngl
e-c
olu
mnt
abl
eandt
wo-c
olu
mnt
abl
e
 Av
alu
eint
heu
nshar
edc
olu
mnmu
stbeas
soc
iat
edwi
the
achv
alu
eint
hes
ingl
e-c
olu
mnt
abl
e

Vi
ews
 Bas
eRe
lat
ion

St
.Mar
y’sUni
ver
sit
y 2
3
Fundament
also
fDat
abas
e Sys
tems Chapt
erI
I

 Name
dre
lat
ionc
orr
esp
ondi
ngt
oane
nti
tyi
nco
nce
ptu
als
che
ma,
who
set
upl
esar
ephys
ical
lys
tor
ed
i
ndat
abas
e.
 Vi
ew
 Dyna
micr
esu
lto
foneo
rmo
rer
elat
ionalo
per
ati
onso
per
ati
ngo
nbas
ere
lat
ionst
opr
odu
ceano
the
r
r
elat
ion.
 Av
irt
ual
rel
ati
ont
hatdo
esno
tne
ces
sar
il
yac
tual
lye
xis
tint
hedat
abas
ebu
tisp
rodu
cedu
ponr
equ
est
,
att
imeo
fre
que
st.
 Co
nte
ntso
fav
iewar
ede
fine
dasaqu
eryo
non
eormo
rebas
ere
lat
ions
.
 Vi
ewsar
edynami
c,me
ani
ngt
hatc
han
gesmadet
obas
ere
lat
ionst
hataffe
ctv
iewat
tri
but
esar
e
i
mme
diat
elyr
efl
ect
edi
nthev
iew.
Pur
pos
eofVi
ews
 Pr
ovi
desp
owe
rfu
landfl
exi
bles
ecu
rit
yme
chani
smbyhi
dingp
art
sofdat
abas
efr
omc
ert
ainu
ser
s.
 Pe
rmi
tsu
ser
stoac
ces
sdat
ainac
ust
omi
zedway,
sot
hats
amedat
acanbes
eenbydi
ffe
ren
tus
ersi
n
di
ffe
ren
tways
,ats
amet
ime
.
 Cans
imp
li
fyc
omp
lexo
per
ati
onso
nbas
ere
lat
ion
s.
Updat
ingVi
ews
 Al
lup
dat
est
oabas
ere
lat
ions
hou
ldbei
mme
dia
tel
yre
fle
cte
dinal
lvi
ewst
hatr
efe
renc
ethatbas
e
r
elat
ion.
 I
fvi
ewi
sup
dat
ed,
unde
rlyi
ngbas
ere
lat
ions
hou
ldr
efl
ectc
hange
.
 The
rear
ere
str
ict
ionso
ntyp
eso
fmo
difi
cat
ionst
hatc
anbemadet
hro
ughv
iews
:
 Up
dat
esar
eal
lo
wedi
fqu
eryi
nvo
lve
sas
ingl
ebas
ere
lat
ionandc
ont
ainsac
andi
dat
eke
yofbas
e
r
elat
ion.
 Up
dat
esar
eno
tal
lo
wedi
nvo
lvi
ngmu
lti
pl
ebas
ere
lat
ions
.
 Up
dat
esar
eno
tal
lo
wedi
nvo
lvi
nga
ggr
egat
iono
rgr
oup
ingo
per
ati
ons
.
 Cl
ass
eso
fvi
ewsar
ede
fine
das
:
 t
heo
ret
ical
lyno
tup
dat
eabl
e;
 t
heo
ret
ical
lyu
pdat
eabl
e;
 Par
tial
lyu
pdat
eabl
e.

St
.Mar
y’sUni
ver
sit
y 2
4
Fundament
also
fDat
abas
e Sys
tems Chapt
erI
I

Rel
ati
onalAl
gebr
a
I
ntr
oduc
tio
n
 Re
lat
ionalal
gebr
aandr
elat
ionalc
alc
ulu
sar
efo
rmall
angu
age
sas
soc
iat
edwi
tht
her
elat
ionalmo
del
.
 I
nfo
rmal
l
y,r
elat
ionalal
gebr
aisa(
high-l
eve
l)p
roc
edu
rall
angu
ageandr
elat
ionalc
alc
ulu
san
on-
p
roc
edu
rall
angu
age
.
 Ho
wev
er,
for
mal
lybo
thar
eequ
ival
entt
ooneano
the
r.
 Al
angu
aget
hatp
rodu
cesar
elat
iont
hatc
anbede
riv
edu
singr
elat
ionalc
alc
ulu
sisr
elat
iona
ll
yco
mpl
ete
.
Rel
ati
onalAl
gebr
a
 Re
lat
ionalal
gebr
aop
erat
ionswo
rko
noneo
rmo
rer
elat
ionst
ode
fineano
the
rre
lat
ionwi
tho
utc
hangi
ng
t
heo
rigi
nalr
elat
ions
.
 Bo
tho
per
andsandr
esu
ltsar
ere
lat
ions
,soo
utp
utfr
omo
neo
per
ati
onc
anbe
comei
npu
ttoano
the
r
o
per
ati
on.
 Al
lo
wse
xpr
ess
ionst
obene
ste
d,j
usta
sinar
ithme
tic
.Thi
spr
ope
rtyi
scal
le
dcl
osu
re.
 Fi
veba
sico
per
ati
onsi
nre
lat
ionalal
gebr
a:Sel
ect
ion,
Pro
jec
tio
n,Car
tes
ianpr
oduc
t,Uni
on,
andSet
Di
ffer
enc
e.
 The
sep
erfo
rmmo
sto
fthedat
are
tri
evalo
per
ati
onsne
ede
d.
 Al
sohav
eJo
in,
Int
ers
ect
ion,
andDi
vi
si
ono
per
ati
ons
,whi
chc
anbee
xpr
ess
edi
nte
rmso
f5bas
ic
o
per
ati
ons
.
Rel
ati
onalAl
gebr
aOper
ati
ons

St
.Mar
y’sUni
ver
sit
y 2
5
Fundament
also
fDat
abas
e Sys
tems Chapt
erI
I

Sel
ect
ion(
orRes
tri
cti
on)

 predicate(R)
 Wo
rkso
nas
ingl
ere
lat
ionRandde
fine
sar
elat
iont
hatc
ont
ainso
nlyt
hos
etu
ple
s(r
ows
)ofRt
hat
s
ati
sfyt
hes
pec
ifi
edc
ondi
ti
on(
pre
dic
ate
).
Ex
ampl
e-Sel
ect
ion(
orRes
tri
cti
on)
 Li
stal
lst
affwi
thas
alar
ygr
eat
ert
han$1
0,0
00.

Salary>10000(Staff)

Pr
ojec
tio
n

 col1,...,coln(R)
 Wo
rkso
nas
ingl
ere
lat
ionRandde
fine
sar
elat
iont
hatc
ont
ainsav
ert
icals
ubs
eto
fR,
ext
rac
ting
t
hev
alu
eso
fsp
eci
fie
dat
tri
but
esande
li
minat
ingdu
pli
cat
es.
Ex
ampl
e-Pr
ojec
tio
n
 Pr
odu
ceal
is
tofs
alar
iesfo
ral
lst
aff,
sho
wingo
nlys
taffNo
,fName
,lName
,ands
alar
yde
tai
ls
.

staffNo,fName,lName,salary(Staff)

Uni
on

RS
 Uni
ono
ftwor
elat
ionsRandSde
fine
sar
elat
iont
hatc
ont
ainsal
lthet
upl
eso
fR,
orS,
orbo
thRand
S,
dup
li
cat
etu
ple
sbe
inge
li
minat
ed.
 RandSmu
stbeu
nio
n-c
omp
ati
ble
.

St
.Mar
y’sUni
ver
sit
y 2
6
Fundament
also
fDat
abas
e Sys
tems Chapt
erI
I

 I eIandJt
fRandShav upl
es,
res
pec
tiv
ely,
uni
oni
sobt
aine
dbyc
onc
ate
nat
ingt
hemi
ntoo
ner
elat
ion
wi
thama
ximu
mo I+J
f( )tu
ple
s.
Ex
ampl
eLi
stal
lci
ti
eswhe
ret
her
eise
ithe
rabr
anc
hoffi
ceo
rap
rop
ert
yfo
rre
nt.

c
ity(
Branc
h)c
ity(
Pro
per
tyFo
rRe
nt)

SetDi
ffer
enc
e

R–S
 De
fine
sar
elat
ionc
ons
ist
ingo
fthet
upl
est
hatar
einr
elat
ionR,
butno
tinS.
 RandSmu
stbeu
nio
n-c
omp
ati
ble
.
Ex
ampl
e-SetDi
ffer
enc
e
 Li
stal
lci
ti
eswhe
ret
her
eisabr
anc
hoffi
cebu
tnop
rop
ert
iesfo
rre
nt.

city(Branch)–city(PropertyForRent)

I
nter
sec
tio
n

RS
 De
fine
sar
elat
ionc
ons
ist
ingo
fthes
eto
fal
ltu
ple
sthatar
einbo
thRandS.
 RandSmu
stbeu
nio
n-c
omp
ati
ble
.
 Ex
pre
sse
dus
ingbas
ico
per
ati
ons
:
RS=R–(
R–S)
Ex
ampl
e-I
nter
sec
tio
n
 Li
stal
lci
ti
eswhe
ret
her
eisbo
thabr
anc
hoffi
ceandatl
eas
tonep
rop
ert
yfo
rre
nt.

city(Branch)city(PropertyForRent)

Car
tes
ianpr
oduc
t

St
.Mar
y’sUni
ver
sit
y 2
7
Fundament
also
fDat
abas
e Sys
tems Chapt
erI
I

RXS
 De
fine
sar
elat
iont
hati
sthec
onc
ate
nat
iono
fev
eryt
upl
eofr
elat
ionRwi
the
ver
ytu
pleo
fre
lat
ion
S.
Ex
ampl
e-Car
tes
ianpr
oduc
t
 Li
stt
hen
ame
sandc
omme
ntso
fal
lcl
ie
ntswhohav
evi
ewe
dap
rop
ert
yfo
rre
nt.


( c
li
ent
No,
fName
,l (
NameCl
ie
nt)
)X( c
li
ent
No,
pro
pe
r
tyNo
,co nt(
mme Vie
wing)
)

Ex
ampl
e-Car
tes
ianpr
oduc
tandSel
ect
ion
 Us
ese
lec
tio
nop
erat
iont
oex
trac
tth
oset
upl
eswhe
reCl
ie
nt.
cl
ie
ntNo=Vi
ewi
ng.
cl
ie
ntNo
.

Client.clientNo=Viewing.clientNo((clientNo,fName,lName(Client))(clientNo,propertyNo,
c
omme
nt(
Vie
wing)
))

Car
tes
ianp
rodu
ctandSe
lec
tio
ncanber
edu
cedt
oas
ingl
eop
erat
ionc
all
edaJ
oin.
J
oinOper
ati
ons
 J
oini
sade
riv
ati
veo
fCar
tes
ianp
rodu
ct.
 Equ
ival
entt
ope
rfo
rmi
ngaSe
lec
tio
n,u
singj
oinp
redi
cat
eass
ele
cti
onfo
rmu
la,
ove
rCar
tes
ianp
rodu
ct
o
fthet
woo
per
andr
elat
ions
.

St
.Mar
y’sUni
ver
sit
y 2
8
Fundament
also
fDat
abas
e Sys
tems Chapt
erI
I

 Oneo
fthemo
stdi
ffi
cul
top
erat
ionst
oimp
leme
nte
ffi
ci
ent
lyi
nanRDBMSando
ner
eas
onwh
yRDBMSs
hav
ein
tri
nsi
cpe
rfo
rmanc
epr
obl
ems
.
 Var
iou
sfo
rmso
fjo
ino
per
ati
on
 The
taj
oin
 Equ
ijo
in(
apar
tic
ulart
ypeo
fThe
taj
oin)
 Nat
uralj
oin
 Ou
terj
oin
 Se
mij
oin
Thet
ajo
in(
-j
oin)

R S
F

 De
fine
sar
elat
iont
hatc
ont
ainst
upl
ess
ati
sfyi
ngt
hep
redi
cat
eFfr
omt
heCar
tes
ianp
rodu
cto
fR
andS.

 Thep
redi
cat
eFi
soft
hefo
rmR.
aiS.
biwhe
remaybeo
neo
fthec
omp
ari
sono
per
ato
rs(
<,,
>,,

=,
).
Thet
ajo
in(
-j
oin)
 Canr
ewr
iteThe
taj
oinu
singbas
icSe
lec
tio
nandCar
tes
ianp
rodu
cto
per
ati
ons

R FS=F(
RS)

 De
gre
eofaThe
taj
oini
ssu
mofde
gre
eso
ftheo
per
andr
elat
ionsRandS.
Ifp
redi
cat
eFc
ont
ainso
nly
e
qual
it
y(=
),t
het
ermEqu
ijo
ini
sus
ed.
Ex
ampl
e-Equ
ijo
in
 Li
stt
hen
ame
sandc
omme
ntso
fal
lcl
ie
ntswhohav
evi
ewe
dap
rop
ert
yfo
rre
nt.

cl
( ie
ntNo
,fName
,lNa (
meCl
ie
nt)
) Cl
ie
nt.
cl
ie
ntNo=Vi
ewi
ng.
cl
ie
nt cl
No( ie
ntNo
,pr
ope
rtyNo
,

c
omme
nt(
Vie
wing)
)

Nat
uralj
oin

R S
AnEqu
ijo
ino
fthet
wor
elat
ionsRandSo
veral
lco
mmo
nat
tri
but
esx
.Oneo
ccu
rre
nceo
feac
h
c
ommo
nat
tri
but
eise
li
minat
edfr
omt
her
esu
lt.
Ex
ampl
e-Nat
uralj
oin

St
.Mar
y’sUni
ver
sit
y 2
9
Fundament
also
fDat
abas
e Sys
tems Chapt
erI
I

 Li
stt
hen
ame
sandc
omme
ntso
fal
lcl
ie
ntswhohav
evi
ewe
dap
rop
ert
yfo
rre
nt.

cl
( ie
ntNo
,fName
,lNa (
meCl
ie
nt)
)

cl
( ie
ntNo
,pr
ope
rtyNo
,co
mme
nt(
Vie
wing)
)

Out
erj
oin
 Todi
spl
ayr
owsi
nther
esu
ltt
hatdon
othav
emat
chi
ngv
alu
esi
nthej
oinc
olu
mn,
useOu
terj
oin.

•R S
 (
Left
)ou
terj
oini
sjo
ini
nwhi
cht
upl
esfr
omRt
hatdono
thav
emat
chi
ngv
alu
esi
nco
mmo
nco
lumns
o
fSar
eal
soi
ncl
ude
dinr
esu
ltr
elat
ion.
Ex
ampl
e-LeftOut
erj
oin
 Pr
odu
ceas
tat
usr
epo
rto
npr
ope
rtyv
iewi
ngs
.

propertyNo,street,ci
ty(
Pro
per
tyFo
rRe
nt)

Vi
ewi
ng

Semi
joi
n

 R FS
 De
fine
sar
elat
iont
hatc
ont
ainst
het
upl
eso
fRt
hatp
art
ici
pat
eint
hej
oino
fRwi
thS.
 Canr
ewr
iteSe
mij
oinu
singPr
oje
cti
onandJ
oin:

R FS=A(
R FS)

St
.Mar
y’sUni
ver
sit
y 3
0
Fundament
also
fDat
abas
e Sys
tems Chapt
erI
I

Ex
ampl
e-Semi
joi
n
 Li
stc
omp
let
ede
tai
lso
fal
lst
affwhowo
rkatt
hebr
anc
hinGl
asgo
w.

St
aff St
aff.
branc
hNo=Br
anc
h.br
anc
hNoandBr
anc
h.c
ity=‘
Gla
s w’Br
go anc
h

Di
vi
si
on

RS
 De
fine
sar
elat
iono
vert
heat
tri
but
esCt
hatc
ons
ist
sofs
eto
ftu
ple
sfr
omRt
hatmat
ch
c
ombi
nat
iono
fev
eryt
upl
einS.
 Ex
pre
sse
dus
ingbas
ico
per
ati
ons
:

T1 C(
R)

T2 C(
(SXT1)–R)

T T1–T2

Ex
ampl
e-Di
vi
si
on
 I
dent
ifyal
lcl
ie
ntswhohav
evi
ewe
dal
lpr
ope
rti
eswi
tht
hre
ero
oms
.

cl
( ie
ntNo
,pr
ope
rt (
yNoVi
ewi )(
ng) propertyNo(
rooms=3(
Pro
per
tyFo
rRe
nt)
))

St
.Mar
y’sUni
ver
sit
y 3
1
Fundament
also
fDat
abas
e Sys
tems Chapt
erI
I

Rel
ati
onalCal
cul
us
 Re
lat
ionalc
alc
ulu
squ
erys
pec
ifi
eswhati
stober
etr
iev
edr
athe
rthanho
wtor
etr
iev
eit
.
 Node
scr
ipt
iono
fho
wtoe
val
uat
eaqu
ery.
 I
nfi
rst
-or
derl
ogi
c(o
rpr
edi
cat
ecal
cul
us)
,pr
edi
cat
eisat
rut
h-v
alu
edfu
nct
ionwi
thar
gume
nts
.
 Whe
nwes
ubs
tit
utev
alu
esfo
rthear
gume
nts
,fu
nct
ionyi
el
dsane
xpr
ess
ion,
cal
ldapr
e opo
sit
ion,
whi
ch
c
anbee
ithe
rtr
ueo
rfal
se.
 I
fpr
edi
cat
eco
ntai
nsav
ari
abl
e(e
.g.
‘xi
same
mbe
rofs
taff’
),t
her
emu
stbear rx
angefo .
 Whe
nwes
ubs
tit
utes
omev
alu
eso
fth
isr rx
angefo ,
pro
pos
iti
onmaybet
rue
;fo
rot
herv
alu
es,
itmaybe
fal
se.
 Whe
nap
pli
edt
odat
abas
es,
rel
ati
onalc
alc
ulu
shasfo
r :t
ms upl
eanddo
mai
n.

Readi
ngAs
signment
:Rel
ati
onalCal
cul
us

St
.Mar
y’sUni
ver
sit
y 3
2

You might also like