Fundamentals of Database Systems Module
Fundamentals of Database Systems Module
I
NTRODUCTI
ONTODATABASESYSTEMS
1.1.Overvi
ew
Today, Databasesareessent
ialt
oeverybusi
ness.Theyar
eusedtomaintai
nint
ernal
recor
ds,
topresentdat atocustomersandcli
entsontheWor l
dWideWeb,andtosupportmanyother
commer ci
alpr ocesses.Databases ar
el i
kewise f
ound atthe cor
e ofmany moder n
organi
zat i
ons.
Dat abaseisacol lect
ionofrelateddat aorr ecords.E. g.studentt abl econsistsofname, regno,
mar ks. Iti sacol l
ectionofi nf ormation-pr eferablyr el at
edi nformationandpr eferabl
y
organized. Dat abasei sar eposi toryofdat a,desi gnedt osuppor teffi
cientdat ast orage,
retri
evalandmai ntenance.Adat abasemaybespeci al
izedt ostorebi naryfil
es,document s,
i
mages,v ideos,relati
onaldata,mul ti
dimensi onaldat a,tr ansactionaldat a,analyticdata,or
geogr aphicdatat onameaf ew.Dat abasespl ayacr i
ticalr ol
ei nal mostal lar easwher e
comput er
s are used,i ncl
uding busi ness,el ect r
oni c commer ce,engi neering,medi cine,
genet i
cs,law,educat ion,andl ibrarysci ence,et c.Incommondi al
ect,thet erm dat abase
referstoacol l
ectionofdat athati smanagedbyaDBMS.Thust heDat abasei sabouthowt o
organizedat a,suppor ti
ngmul ti
pleuser s,eff
icientandef fecti
vedat ar et
r i
eval,securedand
rel
iablestorageofdat a,maintai
ni ngconsi st
entdat a,maki ngi nformationusef ulfordeci si
on
maki ng.
ADBMSi sasof twaresy stem orprogram thatal l
owsaccesst odat acont ainedinadat abase.
Itisasetofsof twar et ool
st hatcontrolaccess,or gani ze,st ore,manage,r etr
ieveand
maintaindat ainadat abase.Itisapower fultoolf orcr eatingandmanagi ngl argeamount sof
dataef ficientl
yandal l
owi ngittoper si
stov erl ongper i
odsoft ime,saf ely.TheDBMSi sa
general-pur posesof twaresy stem thatfaci l
i
t atest hepr ocessesofdef ining,constructing,
manipul ating,and shar ing databases among v arious user s and appl icati
ons. I n any
organizat i
on,i trequiresaccur ateandr eliabledat af orbet terdeci si
onmaki ng,ensur ing
pri
vacyofdat aandcont rol
li
ngdat aeffi
ciently.Theobj ecti
veoft heDBMSi stopr ovidea
conveni entandef f
ectivemet hodofdef i
ning, storing,andr etr
ievingt heinformationstor edin
thedat abase.Exampl es: Micr
osoftAccess, SQL, MySQL, oracle,Sy base,FoxPr obyMi crosof t
,
dBaseVbyBor land,ParadoxbyBor l
andetc.,ar ethev ar
iousDBMSpackages.
ADatabaseapplicat
ionissi mplyaprogr
am t
hati nt
eractswiththedat abaseatsomepoi nt
i
nitsexecut
ion.Databaseappl i
cat
ionist
heprogram thatmakesi tpossibletovi
ew, r
etr
ieve
andupdatei
nformat i
onstoredi nt
heDBMS.Dat abasestouchallaspect sofourl
ives.Some
ofthemajorareasofappl icati
onareasBanking,Airl
ines,Univ
ersit
ies,Manufacturi
ngand
sel
li
ng,Humanr esources,
et c.
Adat abasesy stem isani nt
egratedcol lectionofrelat
edf il
es,alongwiththedet ail
soft he
i
nterpretati
onoft hedat a.Aprimar yaim oft hedatabasesy stem istoprovi
deaconv enient
andef fi
cientwayt ostoreandr etri
evedat astor
edi nadat abase.Adat abasesy stem isa
coll
ectionofappl i
cat i
onprogramst hatinteractwiththedat abaseandsi mplif
iesthet asks
ofmanagi ngthedat aandext r
act i
ngusef ulinf
ormat i
oni nat imelyfashion.Adat abase
system isbasi cal
lyacomput erizedr ecor dkeepingsy stem;thatis,i
ti sacomput eri
zed
system whoseov eral
lpurposei st omai ntai
ninformat i
onandt omaket hatinformation
1
av
ail
abl
eondemand.Dat
abasesy
stem i
ncl
udesbot
hofdat
abaseandDBMSsof
twar
e.
1.2. Basi csofDat abase
Inanor gani zat ion,t hedat ai st hemostbasi cr esour ce.Tor unt heor gani zationef ficient ly,
thepr operor gani zat ionandmanagementofdat ai sessent ial.Thef ormaldef i
nitionoft he
maj ort er msusedi ndat abasesanddat abasesy stemsi sdef inedasf oll
ows:
Dat a:Thet er m dat amaybedef i
nedasknownf act st hatcoul dber ecor dedandst or ed
onComput erMedi a.Iti sal sodef i
nedasr awf act sf rom whi cht her equiredi nf or mat i
on
ispr oduced.
I nfor mat ion:
Dat aandi nfor mat ionar ecl osel yr elatedandar eof tenusedi nt erchangeabl y.Informat i
oni s
not hingbutr efi
neddat a.I not herway ,wecansay ,inf or mat ioni spr ocessed,or gani zedor
summar izeddat a.Accor dingt oBur chet .al.,“Inf ormat ioni sdat at hathav ebeenputi ntoa
meani ngf ulandusef ulcont entandcommuni catedt oar eci pi entwhousesi tt omade
deci sions” .I nfor mat ionconsi stsofdat a,i mages,t ext ,document sandv oice,butal way si n
ameani ngf ulcont ent .Sowecansay ,thati nf or mat ioni ssomet hingmor et hanmer edat a.
Dat aar epr ocessedt ocr eat ei nfor mat ion.Ther eci pientr ecei vest hei nformat i
onandt hen
makesadeci sionandt akesanact ion, whi chmayt ri
gger sot heract ions.
Int heseday s,ther ei snol ackofdat a,butt her ei sl ackofqual i
tyi nf ormat ion.Thequal ity
i
nf ormat ionmeansi nfor mat i
ont hati saccur ate,t imel yandr elev ant ,whi char et het hree
maj orkeyat tri
but esofi nformat ion.
- Accur acy :I tmeans t hatt he i nf ormat ion i sf r
ee f rom er ror s,and i tcl ear lyand
accur at elyr ef lect st hemeani ngofdat aonwhi chi ti sbased.I talsomeansi ti sf ree
from bi asandconv ey sanaccur atepi cturet ot her eci pi ent .
- Ti mel i
ness:I tmeanst hatt her ecipi entsr ecei v et hei nf ormat i
onwhent heyneedi tand
wi thint her equi redt imef rame.
- Rel ev ancy :I tmeanst heusef ulnessoft hepi eceofi nf ormat ionf ort hecor respondi ng
per sons.I tisav erysubj ect i
v emat ter.Somei nformat iont hati sr elevantf oroneper son
mi ghtnotber el ev antf oranot herandv icev er sae. g. ,thepr iceofpr i
nteri sirrelev antf or
a per son who want st o pur chase comput er.So,or gani zat i
on t hathav e good
i
nf or mat ionsy st em,whi chpr oducei nfor mat iont hati saccur ate,t i
mel yandr elev ant
wi l
l sur v iveandt hoset hatdonotr eal i
zet hei mpor tanceofi nf or mat ionwi l
lsoonbeout
ofbusi ness.
Met aDat a
AMet adat ai st hedat aaboutt hedat a.Themet adat adescr ibeobj ect si nthedat abaseand
makeseasi erf ort hoseobj ect st obeaccessedormani pul at ed.Themet adat adescr ibes
thedat abasest ruct ur e,si zesofdat at ypes,const raints,appl ications,aut horizat ionet c.,
thatar eusedasani nt egr alt oolf ori nfor mat ionr esour cemanagement .Ther ear et hree
mai nt y pesofMet adat a:
a)Descr iptiveMet adat a:I tdescr ibesar esour cef orpur posesuchasdi scov eryand
ident ifi
cat ion.I n at raditionall ibrarycat alogi ng t hati sf or m ofmet adat a,t itle,
abst ract ,aut horandkey wor dsar eexampl esofmet adat a.
b)St ruct uralmet adat a:I tdescr ibeshow compoundobj ectsar eputt oget her .The
exampl ei showpagesar eor deredt of orm chapt er s.
2
c)Admi ni st r
at i
v emet adat a:Itpr ov idesi nf ormat iont ohel pmanagear esour ce,such
aswhenandhowi twascr eat ed,f i
let ypeandot hert echni cali nfor mat ion,andwho
canaccessi t.Ther ear esev er al subset sofdat a.
Dat aDi ctionar y
The dat a di ct ionar ycont ai ns i nfor mat ion oft he dat a st ored i nt he dat abase and i s
consul tedbyt heDBMSbef or eanymani pul ati
onoper at ionont hedat abase.I tisani ntegral
par toft hedat abasemanagementsy stemsandst oremet adat ai .e., i
nf ormat ionaboutt he
dat abase, at tri
but enamesanddef initi
onsf oreacht abl ei nt hedat abase.I thel pst heDBAi n
themanagementoft hedat abase, userv iewdef initi
onsaswel last hei ruse.
Dat adi ct i
onar yi sgener atedf oreachdat abaseandgener allyst oresandmanagest he
followingt y pesofi nf ormat ion:
- Thecompl et einf or mat ionaboutphy sicaldat abasedesi gne. g.st or agest r
uctur es,
accesspat hsandf il
esi zeset c.
- Thei nf ormat ionaboutt hedat abaseuser s, thei rr esponsi bi l
iti
esandaccessr ightsof
eachuser .
- Thecompl et einf or mat ionaboutt heschemaoft hedat abase.
- The hi gh l ev eldescr ipt ionsoft he dat abase t ransact ions,appl icat i
onsand t he
inf ormat ionaboutt her elationshi psofuser stot het ransact i
ons.
- Thei nf or mat ionaboutt her elationshi pbet weent hedat aitemsr ef erencedbyt he
dat abaset ransact ions.Thi sinfor mat i
oni shel pfuli ndet er mi ningwhi cht ransact i
ons
ar eaf fect edwhensomedat adef initionsar emodi fi
ed.
The dat a di ctionar ies ar e oft wo t ypes:Act ive dat a di ctionar yand passi v e data
dictionar y.
a)Act iveDat aDi ctionar y :Iti smanagedaut omat ical l
ybyt heDBMSandar eal way s
consi stentwi tht hecur rentst ruct ur eanddef i
nit ionoft hedat abase.Mostoft he
RDBMS’ smai ntai nact i
v edat adi ct ionar i
es.
b)Passi veDat aDi ct i
onar y :Itisusedonl yfordocument ationpur posesandt hedat a
aboutf ields,f iles and peopl e ar e mai ntai ned i ntot he di ctionar yf orcr oss
r efer ences.I tisgener allymanagedbyt heuser soft hesy st em andi smodi fi
ed
whenev ert hest r uctur eoft hedat abasei schanged.Thepassi v edi ct i
onar ymay
notbeconsi st entwi tht hest ruct ur eoft hedat abase,si ncemodi fi
cat i
onsar e
per for medmanual l
ybyt heuser .I ti spossi blet hatpassi vedi ctionar iesmay
cont ai ni nf ormat ionaboutor gani zat i
onaldat at hati snotcomput er izedast hese
ar emai nt ainedbyt heuser s.
Dat abase
Adat abasei sacol lect ionofi nterrelat eddat ast or edt oget herwi thcont r
ol l
edr edundancy
toser veoneormor eappl i
cat ionsi nanopt imalway .Thedat aar est oredi nsuchawayt hat
theyar ei ndependentoft hepr ogr amsusedbyt hepeopl ef oraccessi ngt hedat a.The
appr oachusedi naddi ngt henewdat a,modi f
yingandr etri
ev i
ngt heexi st ingdat af rom the
dat abasei scommonandcont rolledone.I tisal sodef inedasacol lect i
onofl ogically
relateddat ast or edt oget hert hati sdesi gnedt omeeti nfor mat ionr equi rement sofan
organi zat ion.Wecanal sodef i
nei tasanel ect roni cf i
lingsy st em.Theexampl eofa
dat abasei sat el
ephonedi rect oryt hatcont ainsnames,addr essesandt elephonenumber s
3
oft hepeopl estor edi nt hecomput erst orage.
Dat abasesar eor gani zedbyf ields,r ecor dsandf i
les.Thesear edescr ibedbr iefl
yas
foll
ows: -
- Fi elds:I ti
st hesmal lestuni toft hedat at hathasmeani ngt oi tsuser sandi salso
called dat ai tem ordat a element .Name,Addr ess and Tel ephone numberar e
exampl esoff ields.Thesear er epresent edi nthedat abasebyav al
ue.
- Recor ds:iti
sacol lecti
onofl ogicallyr elatedf i
eldsandeachf ieldi spossessi nga
fixednumberofby t esandi soff ixeddat atype.
Alter nat i
vely,wecansayar ecor disonecompl et
esetoff i
eldsandeachf i
eldhav e
somev alue.Thecompl et einformat ionaboutapar t
icularphonenumberi nt hedat abase
repr esent sar ecor d.Recor dsar eoft wot ypesf ixedl engthrecordsandv ari
ablelength
recor ds.
- Fi les:i tisacol l
ect ionofr elatedr ecor ds.Gener all
y,al
lther ecor dsi naf i
lear eof
samesi zeandr ecor dtypebuti ti snotal way st rue.Ther ecordsi naf il
emaybeof
fixedl engthorv ari
abl el engthdependi ngupont hesi zeoft herecor dscont ainedi na
fil
e.The t elephone di rectory cont aining r ecords aboutt he di fferentt el
ephone
hol dersisanexampl eoff i
le.
1.3.Dat aManagementAppr oach( Manual ,File–basedandDat abaseappr oach)
Datamanagement(
keepi
ngy
ourdat
arecor
ds)canbeper
for
medusi
ngt
hef
oll
owi
ngbasi
c
approach:
A.ManualApproach
B.Fi
le-BasedApproach
C.DatabaseApproach
Cur
rent
ly,
all
met
hodsofdat
ahandl
i
ngar
einuset
osomeext
ent
.
A.Manual FileHandl ingSy stems
Thepri
mi ti
veandt radit
ionalwayofi nformat i
onhandl i
ngwher ecardsandpapersare
usedf
ort hepur pose.Themanual fi
lehandlingsy stem:
- Incl udesintensiv ehumanl abor
- Ev entsandobj ectsarewr i
ttenonf i
les(paper )
- Filesar elabeledandst or
edi noneormor ecabinets.
- Thecabi netscoul dbekepti nsaf eplacesf orsecurit
ypurpose.
- Inser t
ionandr etri
evalisdonebysear chingf i
rstfortheri
ghtcabi
nett
henforthe
rightfilethent heinformation.
- Onecoul dhav ei ndexingsystem tofacili
tateaccesst othedata.
Li
mit
ati
onsofManualFi
leHandl
ing
- Probl
em ofDat a Or
gani
zati
on:Suppose we wantt o cancelone ofour
appoi
ntments. Two concept
ual“ ent
it
ies” -
address and cal
endar -
wit
ha
rel
ati
onshi
p between t
hem,linki
ng peopleint he cal
endartothei
rcontact
i
nformati
on.
- Probl
em ofEffi
ciency:Si
zeofy
ourpersonaladdr
essbookisprobabl
ylessthan
onehundredentr
ies,butt
her
earet
hingswe'dli
ketodoqui
cklyandeff
ici
entl
y.
Gener
all
y,Li
mit
ati
onswi
thal
lmanual
syst
emsar
e:
4
• Pronet oerror
• Dif
ficultt
oupdate,r
etr
ieve,
int
egrate
• Youhavet hedatabutiti
sdiff
icul
ttocompi
l
ethei
nfor
mat
ion
• Si
gni f
icantamountofdupli
cat
ionofdata
• Crossr ef
erenci
ngisdi
ffi
cul
t
Sol
uti
onf
orManualf
il
ehandl
ingappr
oach:
Twocomput
eri
zedappr
oachesev
olv
edt
oov
ercomet
hisl
i
mit
ati
ons
- Fi
lebasedapproach Decent
ral
isedsyst
em
- Databaseappr
oach Centr
ali
sedsyst
em
B.Fi
le-
BasedAppr
oach
Tradit
ionalFile processi
ng systems orfil
e based systems wer e an early att
emptt o
comput eri
zethemanualf il
ingsystem.I
tisacoll
ecti
onofappl i
cati
onprogr amsthatperfor
m
servi
cesf orthesy st
em end-user
ssuchast heproduct
ionofr eport
s.Eachpr ogram defi
nes
andmanagesi t
sowndat a.Thisapproachisadecent r
alizedcomput er
izeddat ahandli
ng
method-t odev elopaprogram oranumberofprogramsf oreachdiff
erentappli
cation.Si
nce
everyapplicat
iondefinesandmanagesi t
sowndat a,t
hesy stem i
ssubjectedtoser i
ousdata
dupli
cationproblem.
Li
mit
ati
onsofFi
le-
Basedsy
stems
Dat
aRedundancy(
Dupl
icat
ionofdat
a)
- Samedataishel
dbydiffer
entpr
ogr
ams
- Wastageofst
oragespaceduetoUncont
rol
leddupl
icat
ionofdata
- I
tcoststi
meandmoneyandI tcanl
eadtolossofdataint
egri
ty
Separ
ati
onandi
sol
ati
onofdat
a
- Whendat aisisol
atedi nsepar
atefi
les,i
tismor edif
fi
cultt
oaccessdat
athatshoul
dbe
avai
labl
e.
- Eachprogram maintainsit
sownsetofdat a.Usersofoneprogr
am maybeunaware
ofpotent
ial
lyusefuldataheldbyotherprograms.
- Li
miteddatasharingandspecialcodesfordi f
fer
entqueri
es
Dat
aInconsi
stencyandconf
usi
on
.
Thedat ainaf i
l
esystem canbecomei nconsistentifmorethanoneper sonmodi fi
esthe
dataconcur r
entl
y.I
fther
eexistanumberoff il
eswhi chstoresimi
lardat
ael ementsamong
othersortsofdatathenwhenachangei smadet oapar t
icul
ardata(amongt hecommon
ones).Thischangeneedtobedonet hr
oughoutt hesy st
em wheretherei
ssuchdat astor
ed.
Someoft hedatami ghtbeupdat edandot hersleftast heyarewhi chr esul
tsinan
i
nconsi st
ent inf
ormati
on about t he same phenomena. For exampl e,consider an
organizati
onwhichownsPer sonnel
&Pay rol
lDepar t
ment
o Per
sonnelDepar
tment
:st
oresr
ecor
dsaboutdet
ail
srel
ati
ngt
oeachmember
5
ofanor
g.
o Payrol
lDepartment
:st
ores r
ecor
ds aboutsal
ari
es ofeach st
affofan
organi
zat
ion.
Inbot
hdepar tment,t
her earepotenti
all
ydiff
erentvaluesand/ordif
ferentf
or matsforthe
sameitem anditconsidert
hedupl i
cati
onofdat abetweenthepayrol
landper sonneldepts.
Ifan employee mov es house and the change ofaddr ess i
s communi cated onl
yt o
per
sonnelandnottopay rol
l,
theperson’spaysli
pwi l
lbesenttothewr ongaddress.
Dat adependence
- Fi
l
estruct
ureisdefi
nedi
nthepr
ogr
am codeandi
sdependentont
heappl
i
cat
ion
pr
ogr
ammi
ngl
anguage.
- Each appl
i
cat
ion pr
ogr
am musthav
eit
s own pr
ocessi
ng r
out
ines f
orr
eadi
ng,
i
nser
ti
ng,
updat
inganddel
eti
ngdat
a.
I
ncompat
ibl
efi
lef
ormat
s(LackofDat
aShar
ingandAv
ail
abi
li
ty)
Becausethestructur
eoff ilesi
sembeddedi nt heapplicat
ionpr
ograms,thest ructuresare
dependentontheappl i
cationprogrammi nglanguaget hatiswri
tt
enindi f
ferentlanguages,
andsocannoteasi l
yaccesseachot her’sfil
es.Forexampl e,Personneldeptwr itesin
C/C++programmi nglanguageandpay rolldepart
mentwr i
tesi
nCOBOL/ javaprogr ammi ng
l
anguage.Supposepay rolldepart
mentwant stoknowwhenacer tai
nempl oyeewi l
lbeon
pensi
on.Iti s di
ffi
cultto sharet hi
si nf or
mat i
on unless we have anotherappl icat
ion
progr
ammert owr i
tesoftwar et
oconv er
tt hefil
estosomecommonf ormat.
PoorSecur
it
yandadmi
nist
rat
ion
Si
ncethediff
erentrul
esandappli
cat
ionscanbeestabl
i
shedforeachtypeofaccess(
retr
ieve,
i
nser
t,del
ete,etc.
)toeachofi
nformati
ontothedat
abase.i
tisdi
ffi
cul
ttomanagecentral
ly.
Updat
eAnomal
ies
Themostsigni
fi
cantpr
obl
em exper
iencedbyt
het
radi
ti
onalf
il
ebasedappr
oachofdat
a
handl
i
ngi
sthe“updat
eanomal
i
es”.
• Modi
fi
cat
ionAnomal
ies:A pr
obl
em exper
iencedwhenoneormor
edat
aval
uei
s
modif
iedononeappl
i
cat
ionpr
ogr
am butnotoneot
her
scont
aini
ngt
hesamedat
a
set
.
• Del
eti
onAnomal
ies:Apr
obl
em encount
eredwher
eoner
ecor
dseti
sdel
etedf
rom
oneappl
i
cat
ionbutr
emai
nunt
ouchedi
not
herappl
i
cat
ionpr
ogr
ams.
•I
nser
ti
onAnomal
ies:Apr
obl
em exper
iencedwhenev
ert
her
eisanew dat
ait
em t
o
ber
ecor
ded,
andt
her
ecor
dingi
snotmadei
nal
ltheappl
i
cat
ions.
Besi
destheabov e,t
hemai ntenanceoft heFil
eBasedSy st
em i
sdi
ff
icul
tandt
her
eisno
prov
isi
onforsecuri
ty.Recov
eryisinadequateornon-
exi
stent
.
C.Dat
abaseAppr
oach
ADat abasei
ssharedcol
l
ecti
onoflogical
lyrel
ateddata( andadescript
ionofthisdat
a),
designedtomeettheinf
ormati
onneedsofanor ganizati
on(Centr
ali
zedSy st
em).The
databasehol
dsnotonl
ytheorgani
zat
ion’soperati
onaldatabutalsoadescripti
onofthi
s
6
data.Forthisreason,a database i
s al
so defined as a sel
f-
descr
ibi
ng col
lect
ion of
i
ntegrat
edrecor
ds. Thebasi cl i
mit
ati
onoft hef il
ebasedappr oachthatneedst obe
resol
vedthr
oughdatabaseapproachcanbeat
tributedtotwocommonf actor
s:
- Def
ini
ti
onofdat
aisembeddedi
ntheappl
i
cat
ionpr
ogr
ams,
rat
hert
hanbei
ngst
ored
separ
atel
yandi
ndependent
ly.
- Ther
eisnocont
rolov
ert
heaccessandmani
pul
ati
onofdat
abey
ondt
hati
mposed
byt heappl icat
ionpr ograms.
Therefore,i nor dert oov ercomet hel imit
ationsofaf il
esystem,anew appr oachwas
requi
red.Henceadat abaseappr oachemer ged.Adat abaseisaper sistentcollecti
onof
l
ogicallyr el
ateddat a.Thei ni
t i
alatt
empt sweret opr ovi
deacent r
alizedcol l
ectionofdat a.A
databasehasasel f
-describingnatur e.Itcontainsnotonl ythedat abutal sot hecompl ete
defi
niti
onoft hedat abasest ruct
ureandconst raints,whicharestor edinasy stem catalog.
A DBMS manages t his dat a.Ital lows dat a shar i
ng and integrat
ion ofdat a ofan
organizationi nasi ngledat abase.DBMScont rolsaccesst othisdat aandt husneedst o
provi
def eaturesfordat abasecr eation, dat
amani pulat
ionsuchasdat av aluemodi fi
cation,
dataret r
ieval,dataintegri
tyandsecur ityetc
Benef
it
sofDatabaseapproachsystems
▪ Datacanbeshared
o Twoormor euser scanaccessandusesamedat ai
nst
eadofstor
ingdatain
redundantmannerforeachuser
o ADBMSal l
owst heshari
ngofdatabaseunderit
scontr
olbyanynumberof
appli
cati
on programs or users. A database bel
ongs to the enti
re
organi
zati
onandi sshar
edbyallaut
hori
zedusers
•I
mpr
oveddat
aaccessi
bil
it
y
o DBMSut il
izestechniquest
ostoreandret
riev
et hedataeff
icientl
yatleast
forunf
oreseenqueries.AcomplexDBMSshouldbeabl et
opr ovideser
vices
toenduser s,
wheretheycanef
fici
ent
lyr
etr
ievethedataal
mosti mmediat el
y.
• Redundancycanber
educed:
o I
ndat abaseapproachdatacanbestoredatasi nglepl
aceorwit
hcontr
oll
ed
redundancy under DBMS,whi ch sav es space and does not permit
i
nconsistency.
▪ Qual
it
ydat a can bemai ntai
ned:thedif
ferentint
egr i
tyconstrai
ntsi
nthedat abase
appr
oachwillmaintai
nthequali
tyl
eadi
ngtobet t
erdecisionmaking.
•I
nconsi
stencycanbeav
oided:cont
rol
l
eddat
aredundancywi
l
lav
oidi
nconsi
stency
oft
hedat
aint
hedat
abaset
osomeext
ent
.
• Tr
ansact
ionsuppor
tcanbepr
ovi
ded:
o At r
ansacti
onisdef i
nedast heuni
tofwork.Forexample,abankmaybe
i
nvolved i
nat ransact
ion wher
ean amountofBr.
5000 i
st r
ansfer
red f
rom
accountX toaccountY. DBMSal soall
owsmulti
pletr
ansacti
onstooccur
si
mul t
aneousl
y.
7
o Basi cdemandsofanyt ransacti
onsuppor tsy st emsar eimpl antedinaf ullscale
DBMSandi tsuppor tforconcur r
entt ransacti
ons.
▪ I mpr ov edBackupandRecov ery
Af i
le-basedsy stem mayf ailt opr ovidemeasur estopr ot ectdataf r
om sy stem f ail
ures.
Thisliessol elyont heuserbyt aki ngbackupsper i
odical ly.DBMSpr ov i
desf acil
it
iesf or
recovering t hehar dwar eand sof twar efail
ures.A backup and r ecov er
ysubsy stem i s
responsi bl
ef orthis.Incaseapr ogram f ai
l
s,itr estor
est hedat abaset oast ateinwhi chi t
wasbef or et heexecut ionoft hepr ogr am.
▪ I ntegr i
tycanbemai ntained:
Dataatdi fferentappl icationswi l
lbei nt
egratedt ogetherwi thadditi
onalconst raintsto
faci
lit
ateshar eddat ar esour ce.
o Dat aI ntegrit
yr eferst ov al
idi
tyand consi st encyofdat a.Dat aI ntegrit
y
meanst hatt hedat ashoul dbeaccur ateandconsi stent.Thisisdoneby
pr ovi
dingsomechecksorconst raints.Thesear econsistencyr ul
est hatthe
dat abasei snotper mittedt ov i
olate.Const raint smayappl yt odat ai t
ems
wi thi
nar ecor dorr el
ationshipsbet weenr ecor ds.
• Secur
it
ymeasur
escanbeenf
orced(
impr
ovedsecur
it
y):
Datai sv i
talt oanyor gani zationandal soconf i
dent ial.I
nashar edsy stem wher emul t
iple
usersshar et hedat a,al linf ormat i
onshoul dnotbeshar edbyal luser s.Forexampl e,t he
sal
aryoft heempl oyeesshoul dnotbev i
siblet oany oneot hert hant hedepar tmentdeal ing
i
nt his.Hence,dat abaseshoul dbepr otectedf rom unaut hor i
zeduser s.Thi sisdoneby
Database Admi nistrat or( DBA)by pr oviding t he user names and passwor ds onlyt o
authorizeduser saswel lasgr anti
ngpr ivi
legesort het ypeofoper at i
onal lowed.Thi si s
donebyusi ngsecur ityandaut horizationsubsy stem.Onl yaut hor izeduser smayuset he
databaseandt heiraccesst ypescanber estrictedt oonl yr etri
ev al,inser t
,updat eordel ete
oranyoft hese.Forexampl e,t heBr anchManagerofanycompanymayhav eaccesst oall
datawher east heSal esAssi st antmaynothav eaccesst osal ar ydet ails.Theshar eddat a
canbesecur edbyhav ingdi fferentl evelsofcl ear anceandot herdat asecur it
ymechani sms.
▪ Repr esent ingcompl exr elationshi pamongdat a
o Adat abasemayi ncl udev arieti
esofdat ainterrelatedt oeachot heri nmany
way s.A DBMS musthav et he capabi li
tyt or epresenta v ariet
y of
relationshi psamongt hedat aaswel last oretrieveandupdat er elateddata
easi lyandef f
icient l
y.
•I
mpr
oveddeci
sionsuppor
t:t
hedat
abasewi
l
lpr
ovi
dei
nfor
mat
ionusef
ulf
ordeci
sion
maki
ng
• St
andar
dscanbeenf
orced:Thedi
ff
erentway
sofusi
nganddeal
i
ngwi
thdat
aby
di
ff
erentuni
tsoft heor
gani
zat
ioncanbebal
ancedandst
andar
dizedbyusi
ng
dat
abaseapproach.
• LessLabour
:Unl
i
ket
heot
herdat
ahandl
i
ngmet
hods,dat
amai
ntenancewi
l
lnot
demandmuchr
esour
ce
• Cent
ral
ized i
nfor
mat
ion cont
rol
:Si
ncer
elev
antdat
aint
heor
gani
zat
ionwi
l
lbe
st
oredatoner
eposi
tor
y,i
tcanbecont
rol
l
edandmanagedatt
hecent
ral
lev
el.
8
• Dat
aIndependence:I
nthef
il
e-basedsy
stem,
thedescr
ipt
ionsofdat
aandl
ogi
cfor
accessingthedataarebui l
tintoeachappl icat
ionprogr am maki ngt hepr ogram
mor edependentondata.Achangei nt hestruct
ureofdat amayr equireal
terations
toprograms.DBMSsepar atesdatadescr ipt
ionsfrom data.Hencei tisnotaf fected
bychanges.Thi siscalled DataI ndependence,wher edet ai
l
sofdat aar enot
exposed.DBMSpr ovi
desanabst r
actv iewandhi desdetails.Appli
cationsinsulated
fr
om howdat aisstr
uctur
edandst ored
▪ Compact ness:Si
nceitisanel ectr
oni cdat ahandli
ngmet hod,t hedatai sst ored
compactly(novol
uminouspapers).
▪ Speed:Dat astor
ageandr et
riev
alisf astasitwi l
lbeusingt hemoder nfastcomput er
systems.
Li
mitat
ionsandr i
skofDatabaseappr oach
•Introducti
onofnewpr of
essi
onalandspeciali
zedpersonnel
• Highcosttobeincurr
edtodevel
opandmai nt
ainthesystem
• Compl exbackupandrecov
eryservi
cesfr
om t heusersperspect
ive
• Reducedper f
ormanceduetocentr
ali
zati
onanddat aindependency
• Highimpactont hesy
stem whenfai
lur
eoccur stothecentralsy
stem
1.
4.Character
isti
csoft heDatabaseAppr oach
Themai ncharact
eristi
csofthedatabaseapproacharethefoll
owing:
▪ Sel f-
descri
bingnatureofadat abasesystem
▪ I nsul
ationbetweenprogramsanddat a,anddat
aabstract
ion
▪ Suppor tofmul ti
plevi
ewsoft hedat a
▪ Shar ingofdat aandmul t
iusertr
ansacti
onprocessi
ng
1.Sel f-
Descr ibingNat ureofaDat abaseSy st em
Af undament alchar acteri
sti
coft hedat abaseappr oach i st hatt hedat abasesy stem
cont ainsnotonl yt hedat abasei tselfbutal soacompl etedef i
niti
onordescr i
pt ionoft he
databasest ructureandconst r
aints.Thi smet a-data( i
.e.,dat aaboutdat a)isst oredi nt he
so-cal l
edsy stem cat alog, whichcont ainsadescr i
pti
onoft hest r
uct ureofeachf ile,thety pe
andst oragef ormatofeachf ield,andt hev ariousconst raintsont hedat a(i
.e.,condi ti
ons
thatt hedat amustsat i
sfy).Thesy st em cat alogi susednotonl ybyuser sbutal sobyt he
DBMSsof twar e,whi chcer t
ainlyneedst o" know"how t hedat ai sst r
uctured/organi zedi n
ordert oi nterpreti ti
namannerconsi stentwi tht hatstr
uct ur e.
2.I nsulationbet weenPr ogramsandDat a,andDat aAbst raction
Int heDBMSpr ovidesaconcept ualorl ogicalv i
ewoft hedat at oappl i
cati
onpr ogr ams,so
thatt heunder l
yingi mpl ement ati
onmaybechangedwi thoutt hepr ogramsbei ngmodi f
ied.
(Thisi srefer redt oaspr ogram- datai ndependence. )
Progr am- oper ationi ndependence:I nobj ect -orientedandobj ect-relat
ionalsystems,user s
candef i
neoper ationsondat aaspar toft hedat abasedef initi
ons.Anoper ati
on( alsocal led
af unct i
onormet hod)i sspeci fi
edi nt wopar ts.Thei nt
er face( orsignat ur
e)ofanoper ation
i
ncl udest heoper ati
onnameandt hedat at ypesofi tsar gument s( orparamet ers).The
i
mpl ement at i
on( ormet hod)oft heoper ationi sspeci fiedsepar atelyandcanbechanged
9
wi t
houtaf fect ingt hei nter face.Userappl icat
ionpr ogr amscanoper ateont hedat aby
i
nv oki ngt heseoper ationst hr ought hei rnamesandar gument s,r egar dlessofhow t he
oper at ionsar ei mpl ement ed.Thi smaybet er medpr ogr am- oper at i
oni ndependence.
Dat aabst ract i
on:Thechar act eristict hatal l
owspr ogr am- dat ai ndependenceandpr ogram
oper at ion i ndependence i s cal led dat a abst raction.A DBMS pr ovides user s wi tha
concept ual repr esent at i
onofdat at hatdoesnoti ncludemanyoft hedet ailsofhowt hedat a
i
sst or edorhowt heoper at i
onsar ei mpl ement ed.Inf ormal l
y,adat amodeli sat ypeofdat a
abst ract iont hati susedt opr ov i
det hi sconcept ualr epr esent at i
on.Thedat amodeluses
l
ogi calconcept s, suchasobj ect s, thei rpr oper t
ies,andt hei rinterr elationshi ps, t
hatmaybe
easi erf ormostuser st ounder st andt hancomput erst or ageconcept s.Hence,t hedat a
modelhi desst or ageandi mpl ement at i
ondet ail
st hatar enotofi nter estt omostdat abase
user s.
3.Suppor tofMul tipleVi ewsoft heDat a
Adat abaset ypical l
yhasmanyuser s,eachofwhom mayr equireadi fferentper spect i
veor
viewoft hedat abase.Av iewmaybeasubsetoft hedat abaseori tmaycont ainv i
rtualdat a
thati sder i
v edf rom t hedat abasef ilesbuti snotexpl icitlyst ored.Amul tiuserDBMSwhose
user shav eav arietyofdi stinctappl icat i
onsmustpr ov idef acilitiesf ordef iningmul tiple
views.
4.Shar ingofDat aandMul tiuserTr ansact ionPr ocessi ng
Amul tiuserDBMS,asi tsnamei mpl ies,mustal l
owmul tipleuser st oaccesst hedat abase
att hesamet ime.Thi si sessent i
ali fdat af ormul ti
pl eappl i
cationsi st obei ntegr atedand
mai nt ainedi nasi ngledat abase.TheDBMSmusti ncl udeconcur rencycont rolsof twar et o
ensur et hatsev eraluser st ryi
ngt oupdat et hesamedat adosoi nacont rolledmannerso
thatt her esul toft heupdat esi scor rect .Forexampl e,whensev eralr eservat ionagent st ry
toassi gnaseatonanai rlinef light ,t heDBMS shoul densur et hateachseatcanbe
accessedbyonl yoneagentatat imef orassi gnmentt oapassenger .Theset ypesof
appl icat i
onsar egener allycal led onl inet ransaction pr ocessi ng ( OLTP)appl ications.A
fundament alr ol eofmul tiuserDBMSsof twarei st oensur et hatconcur r
entt r
ansact ions
oper at ecor rectlyandef ficient ly.
Theconceptofat ransact ion hasbecomecent ralt o manydat abaseappl ications.A
transact ioni sanexecut ing pr ogr am orpr ocesst hati ncludesoneormor edat abase
accesses,suchasr eadingorupdat ingofdat abaser ecor ds.TheDBMSmustenf or ce
sev er alt ransact ion pr oper t
ies.The i solation proper ty ensur es t hateach t ransact ion
appear st o execut ei ni solat i
on f rom ot hert ransact ions,ev en t hough hundr eds of
transact ionsmaybeexecut i
ngconcur rently.Theat omi citypr oper tyensur est hatei theral l
thedat abaseoper ationsi nat ransact ionar eexecut edornot .
1.
5.DBMS,
DBMSComponent
sandi
tsenv
ironment
DBMSi sasof t
warepackagedesi gnedtostoreandmanagedatabases.Itmanagesand
control
saccesstothedatabase.Populardat
abases:Or
acl
e,MSSQLser
ver,DB2,
Sybase,
MS
-Access,FoxPr
o,et
c…
TheDBMSi sthesoft
warethathandlesallaccesst ot
hedatabase. ItisaSoftware
package used for provi
ding ef
fi
cient, conveni
ent and safe mul t
i-
user (
many
people/
progr
amsaccessi
ngsamedat abase,orevensamedata,si
multaneousl
y)st
orage
10
ofandaccesstomassiveamountsofpersi
stent(
dataout
li
vesprogramsthatoper
ateonit)
dat
a.ADBMSal soprov
idesasystemati
cmet hodforcr
eati
ng,updati
ng,st
ori
ng,r
etri
evi
ng
dat
ainadat abase.
Themaj
orf
unct
ionsofat
ypi
cal
DBMSi
ncl
udet
hef
oll
owi
ng:
Dat adef initi
on:TheDBMSmusti ncludel anguagepr ocessorcomponent s(must
hav eadat asubl anguagewi thfeaturesf ordat adef i
nit
ionanddat amani pulation
act i
viti
es)f oreachoft hev ariousdat adef init
ionl anguages( DDLs) .Thati s,it
mustbe abl et o acceptdat a defi
ni t
ions( externalschemas,t he concept ual
schema,t hei nternalschemaandal lassoci atedmappi ngs)insour ceform and
conv er tthem t otheappr opriateobjectf or m.
Dat amani pul ati
on: TheDBMSmusti ncl udeadat amani pulati
onlanguage( DML)
processorcomponentt hatwoul denabl et heDBMSmustt ohandl er equestsfrom
theusert or etri
eve,updat eordel eteexi st i
ngdat aint hedat abase,oraddnew
dat at ot hedat abase.
Dat asecur it
yandi ntegri
ty:TheDBMSmustmoni t
oruserr equest sandr eject
anyat tempt st ov i
olatethesecur i
tyandi nt egrit
yr ulesdef i
nedbyt heDBA.
Dat ar ecov eryandconcur r
ency :TheDBMSorel sesomeot herrelatedsof t
war e
component ,usual ly call
ed t he transact ion manager mustenf orce certain
recov er yandconcur rencycont rol
s.
Dat adi ctionar y:TheDBMSmustpr ov ideadat adi ct
ionaryf unction.Thedat a
dictionar ycont ainsdef i
niti
onsofobj ectsi nt hesy stem suchast abl esandt able
relationshi psandr ul
esdef i
nedonobj ects.
Havi
ngalloftheabov
efunct
ionsinmi nd,af
ull
-scal
eDBMSshoul
datl
easthav
ethe
f
oll
owingser
vicest
oprov
idet
ot heuser
.
- Datastor
age,ret
rievalandupdat
eint
hedat
abase
- Auseraccessibl
ecat al
ogue
- Transact
ion supportser vi
ce:ALL orNONE tr
ansact
ion,whi
ch mi
nimi
ze dat
a
i
nconsi
stency
.
- Concur
rencyContr
olServi
ces:accessandupdateont hedat
abasebydi
ff
erent
user
ssimult
aneousl
yshouldbei
mplementedcor
rect
ly.
- Recover
ySer
vices:amechani
sm f
orr
ecov
eri
ngt
hedat
abaseaf
teraf
ail
uremustbe
avai
labl
e.
- Author
izat
ionServi
ces(Secur
it
y): mustsupporttheimpl
ement
ati
onofaccess
andauthori
zat
ionserv
icet
odatabaseadmini
str
atoranduser
s.
- SupportforDat
aCommunicat
ion:shouldpr
ovi
dethefaci
l
ityt
oint
egr
atewi
thdat
a
tr
ansfersoft
wareordat
acommuni cat
ionmanager
s.
- Int
egrit
yServices:rul
esaboutdat
aandthechanget
hattookpl
aceonthedat a,
corr
ectness and consist
encyofstor
ed dat
a,and qual
i
tyofdata based on
businessconstrai
nts.
- Ser
vicest
opr
omot
edat
aindependencybet
weent
hedat
aandt
heappl
i
cat
ion
- Uti
li
tyser
vices:set
sofuti
li
tyser
vicefaci
l
iti
eslikeI
mport
ing dat
a,St
ati
sti
cal
anal
ysi
ssupport,I
ndexr
eor
gani
zat
ionandGarbagecol
l
ect
ion
11
ADBMSi salsosoftwarepackageusedt odesi
gn,manage,andmai ntai
ndat abases.
EachDBMSshoul dhavef aci
li
ti
estodefinethedatabase,manipul
atethecontentofthe
databaseandcontrolt
hedat abase.Thesefaci
li
ti
eswi l
lhelpthedesigner
,theuseras
wellasthedatabaseadmi ni
str
atortodischar
getheirresponsi
bil
i
tyindesigni
ng,using
andmanagingthedatabase.
Ther
efore,DBMS pr
ovi
des t
he abov
efunct
ions usi
ng t
he f
oll
owi
ng f
aci
l
iti
es or
l
anguages:
Dat
aDefi
nit
ionLanguage(DDL)
Dat
aManipulat
ionLanguage(
DML)
Dat
aDi
cti
onar y
Dat
aContr
olLanguage(DCL)
DataDef ini
tionLanguage( DDL) :Languageusedt odef ineeachdat aelementr equir
ed
bytheor ganization.I
tisCommandsf orset ti
ngupschemaoft hedat abase.I
tisusedt o
setupadat abase, cr
eate,deleteandal t
ert ablewi tht hef acili
tyofhandl i
ngconst rai
nts.
Iti
ncludesSQLCommands: CREATE, ALTER, DROP, &RENAME
Data Mani pulat i
on Language ( DML) :A cor e command used by end- user s and
programmer st ost or
e, r
etr
ieve,andaccesst hedat ai nt hedat abase.Sincether equir
ed
dataorquer ybyt heuserwi llbeextractedusi ngt hist ypeofl anguage,itisalsocal l
ed
“QueryLanguage” .Itincl
udesSQLCommands:I NSERTI NTO,DELETE,TRUNCATE,&
UPDATE
DataDi cti
onar y
:I ti
susedt ost oreandor ganizeinformat i
onaboutt hedatastoredint he
database.Dat abaseisasel f-descri
bingsy stem.Ther eforeDat adictionar
ydescr i
besdat a
defi
niti
on&det aildescri
pti
onofdat ainthedat abase.I tisal soknownasmet adat a-data
aboutdat a.
DatabaseCont rolLanguage:Dat abaseisshar edresour cet hatdemandscont rolofdata
accessandusage.DBAcont r
olstheov eralloperationofadat abaseandDBcont rol
l
anguagesar ecommandst hatwi l
lhel pt hedat abaseadmi ni
stratorto controlthe
database.ItincludeSQLCommands: GRANT&REVOKE
- Gr
ant:gi
vespr
ivi
l
egest
oaccesst
hedat
abaseorpar
ti
cul
arobj
ectwi
thi
nthe
dat
abaseandal
soSt
oresdat
abaset
ransact
ions
- Revoke:r
etakeorr
emov
ethegi
ven pr
ivi
l
egest
o accesst
hedat
abaseor
parti
cularobjectwithi
nthedatabase.
1.6.DatabaseSy stem Environment
TheDBMSsof t
war etogetherwiththeDat abasei scalledadat abasesy stem.I nother
words,itcanbedef inedasanor gani
zati
onofcomponent sthatdef i
neandr egul
atethe
coll
ecti
on,storage,managementanduseofdat ainadat abase.Fur ther
more, i
tisasy st
em
whoseov erallpurposeistor ecordandmaintaininfor
mat ion.Adat abasesy stem consi
sts
offiv
emaj orcomponent sdat abasesyst
em environment.Thesear e:
a) Hardwar e b)Software c)Data d)Procedures e)Peopl
e
12
a)Hardwar e:I tist hephy sical par tsofthecomput er&comput errel
at eddev icethatwecan
seeandt ouch.TheDBMSandt heappl icati
onneedsHar dwar et or un.Dependsont he
organizat ionsr equi r
ementandt heDBMSused.( Somer unonapar ticularhar dwar eand
OSwhi l
eot her sonawi dev arietyofHar dwar e).Eg.I nacl ientser verar chi t
ecture,Cl i
ent
usesfr ontendofDBMS&Dat abaseSer verser vesasbackendofDBMS
b)Softwar e:I tisacol l
ecti
onofpr ogramsori nstructi
onst hatgui dest hecomput erwhatt o
doandmakesi tf uncti
onal.I tcomposedt heDBMSandt heappl i
cat iont ogetherwi tht he
r
d
operatingsy stem andappl icat i
onpr ogramscanbewr itteni n3 gener ati
onl anguage.
DBMSmayhav ei t
sownf our thgener ati
ont oolsr eport,f orms,gr aphsandappl ication
generat ors.
c)Data:ist hemosti mpor tantcomponentofDBMSf rom t heenduserpoi ntofv iew.I t
contai
nbot ht heoper ationalandMet adat a.Thest r
uct ur eoft hedat abasei scal l
ed
schema.
d)Procedur es:I tr ef ersthei nst ructi
onsorr ulest hatgov er nsthedesi gnanduseoft he
database.I ti st hest epst obef oll
owedt oaccessadat abaseandt oper f
orm anyt asks
withadat abases.
Thi
smayconsi stof :Logont ot heDBMS,Useapar ti
cularDBMSf acilit
ies,St artandst opof
DBMSandMaki ngbackupcopi esoft hedat abase.
e)People: Peopl ecanbei dent i
fiedinf ourdistincttype:Dat aandDat abaseAdmi nistrator
,
DatabaseDesi gner ,
Applicat i
onDev eloperandEnduser s
1.
7.Dat
abaseDev
elopmentLi
feCy
cle
Asiti
sonecomponentinmostinf
ormati
onsystem devel
opmentt asks,t
hereareseveral
st
epsindesi
gni
ngadatabasesy
stem.Heremoreemphasi sisgiventothedesignphases
oft
hesyst
em devel
opmentl
if
ecycl
e.Themajorstepsindatabasedesignare;
1.Planni
ng:thati
si dent
if
ying i
nfor
mat
ion gap i
n an or
gani
zat
ion and pr
opose a
databasesol
uti
ontosolvet
heproblem.
2.Analysi
s:t
hatconcentr
atesmoreonfactfi
ndi
ngaboutt heproblem ort
heopport
unit
y.
Feasibi
l
ityanaly
sis,requi
rementdet
erminat
ion and st
ructur
ing,and sel
ect
ion ofbest
designmethodarealsoperfor
medatthi
sphase.
3. Desi
gn:i
ndatabasedesigni
ngmoreemphasi
sisgi
vent
othi
sphase.Thephasei
s
f
urt
herdi
vi
dedi
ntothr
eesub-phases.
a.ConceptualDesign:conci
sedescript
ionofthedata,datat
ype,rel
ati
onshipbet
ween
data and constr
aints on t
he data.Thereis no i
mplementati
on orphy si
caldet
ail
consi
derat
ion.Iti
susedt oeli
citandstr
uct
ureall
inf
ormationr
equir
ements
b.LogicalDesign:ahigherlev
elconceptualabstracti
onwi
thsel edspeci
ect f
icdat
a
modelt oimplementthedatastr
uct
ure.Itispart
icularDBMSi
ndependentandwit
hno
otherphysicalconsi
der
ati
ons.
c.Phy
sicalDesi
gn:physi
cali
mplementati
onoft
heupperlev
eldesi gnofthedat
abase
wit
hrespecttointer
nalstor
ageandf il
estr
uct
ureofthedat abasefortheselect
ed
DBMS.Itisusedt
odev el
opall
technol
ogyandor
gani
zat
ionalspecif
icat
ion.
4. Impl
ement
ati
on:
thet
est
inganddepl
oymentoft
hedesi
gneddat
abasef
or
use.
13
5. Operat
ion and Support: admini
ster
ing and mai
ntai
ning t
he oper
ati
on oft
he
dat
abasesy
stem andprovi
dingsuppor
ttousers.
1.
8.Usersandactor
sofDat
abasesystem
1.
8.1.DatabaseUsers
AdatabaseUsersmaybedi
videdi
nto
- Thosewhoact
ual
l
yuseandcont
rol
thedat
abasecont
ent
,andt
hosewhodesi
gn,
dev
elopandmai
ntai
ndat
abaseappl
i
cat
ionscal
l
ed“
Act
orsont
heScene”
- Thosewhodesi
gnanddev
elopt
heDBMSsof
twar
eandr
elat
edt
ool
s,andt
he
comput
ersy
stemsoper
ator
scal
l
ed“
wor
ker
sbehi
ndt
heScene”
Actorsont heScene
1.Dat abaseAdmi nistrat or(DBA) :
They ar e chiefadmi nist r
ator ,who ov ersees and manages t he dat abase sy stem
(i
ncluding thedat a and sof tware).Dut iesi ncl
udeaut horizi
ng user st o accesst he
database,coor dinating/ moni tori
ngi tsuse,acqui r
inghar dware/sof t
waref orupgr ades,
etc.TheDBAi saccount abl ef orpr oblemssuchassecur it
ybreachesandpoorsy stem
responset i
me.I nlargeor ganizations,theDBAmi ghthav easuppor tstaf
f.
DataAdmi nistr
ator( DA) :isr esponsibl eonmanagementofdat ar esources.I nvol
v esin
databasepl anning,dev elopment ,mai ntenanceofst andar dspoliciesandpr oceduresat
theconcept ualandl ogi cal desi gnphases.
2.DatabaseDesi gner s:
Theyar eresponsi blefori dent i
fyi
ngt hedat atobest oredandf orchoosi nganappr opriate
wayt oor ganizei t.Dat abasedesi gnerst ypi
call
yi nteractwi t
heachpot entialgroupof
usersanddev elopv i
ewsoft hedat abaset hatmeett hedat aandpr ocessingr equir
ement s
oft hese gr oups.The f inaldat abase desi gn mustbe capabl e ofsuppor t
ing t he
requir
ement sofal lusergr oups.
Wehav etwo di
sti
nct
ionsofdat abasedesi
gners,oneinvol
vi
ng i
nthel
ogi
caland
concept
ual
desi
gnandanotheri
nvolvi
nginphy
sicaldesi
gn.
o Logi
cal
andconcept
ual
dat
abaseDesi
gner
s
- I
dent
if
ies dat
a(ent
it
y,at
tri
but
es and r
elat
ionshi
p)r
elev
antt
othe
or
gani
zati
on
- I
dent
if
iesconst
rai
ntsoneachdat
a
- Under
standdat
aandbusi
nessr
ulesi
ntheor
gani
zat
ion
- Seesthedat
abaseindependentofanydatamodelatconcept
uall
eveland
consi
deronespeci
fi
cdatamodel atl
ogicaldesi
gnphase.
- Concer
nedwithident
if
yingt
hedat
a,ent
it
iesandat
tr
ibut
es,r
elat
ionshi
ps
andconst
rai
nts
- Needacompl
eteknowl
edgeoft
heor
gani
zat
ion'
sdat
aandbusi
ness
r
ules
o Phy
sical
dat
abaseDesi
gner
s
14
- Takelogi
caldesi
gnspeci
fi
cat
ionasi
nputanddeci
dehowi
tshoul
dbe
physi
call
yreal
i
zed.
- Mapthelogi
caldatamodelont hespeci
fi
edDBMSwi t
hrespectt
o
t
abl
esandint
egri
tyconst
rai
nts.(
DBMSdependentdesi
gni
ng)
- Sel
ectspeci
fi
cst
oragest
ruct
ureandaccesspat
htot
hedat
abase
- Desi
gnsecur
it
ymeasur
esr
equi
redont
hedat
abase
- Deci
dehowt
hel
ogi
cal
dat
abasedesi
gneri
stobephy
sical
l
yreal
i
zed
- Mapt
hel
ogi
cal
dat
abasedesi
gni
ntoasetoft
abl
es
3.EndUsers:
These ar
e persons who access t
he dat
abase f
orquer
ying,updat
ing,and r
epor
t
gener
ati
on.Therear
eseveralcat
egori
esofenduser
s:
- Casualend user
s:user
s who use dat
abase occasi
onal
l
y,needi
ng di
ff
erent
i
nfor
mationeacht
ime;usequer
ylanguaget
ospeci
fyt
hei
rrequest
s;t
ypi
cal
l
ymi
ddl
e-
orhi
gh-
level
managers.
- Nai
ve/
Par
amet
ri
cenduser
s:t
hebi
ggestgr
oupofuser
s;f
requent
lyquer
y/updat
e
the database usi ng standard canned transacti
ons t hathav e been careful
ly
programmedandt est
edi nadv ance.
o Unawar eoft heDBMSandt heDatabase
o Accessdat abasedependont hesi mplicit
yoft heGUI( Graphi
calUser
I
nterf
ace)
o Onl yaccesst hedatabasebasedont hei
raccessl evelanddemand
o Usest andar dandpr e- speci
fi
edtypesofquer i
es.
o Exampl es:
bankt ell
erscheckaccountbal ances, postwit
hdrawals/deposit
s
Reser v ati
oncl erksforai
rl
ines,hot el
s,etc.
,checkav ail
abil
it
yof
seats/roomsandmaker eservati
ons.
- Sophi
sti
cat
edenduser
s:ar
ethosewhot
hor
oughl
yfami
l
iar
izet
hemsel
veswi
th
thefaci
l
iti
esoft heDBMSinordert
oimpl
ementt
hei
rownappl
icat
ionst
omeet
thei
rcompl exrequi
rement
s.Theyaremostoft
hetimeengi
neer
s,sci
ent
ist
s,
busi
nessanalyst
s,et
c
o Areuser
sfami
l
iarwi
tht
hest
ruct
ureoft
heDat
abaseandf
aci
l
iti
esoft
he
DBMS.
o Under
standcompl
exr
equi
rement
swi
thhi
gherl
evel
quer
ies
o Ar
emostoft
het
imeengi
neer
s,sci
ent
ist
s,busi
nessanal
yst
s,et
c
o Mayusehigh-
lev
elquer
ylanguages(
SQL)t
oper
for
m t
her
equi
red
oper
ati
on
o Mayev
enwr
it
eappl
i
cat
ionpr
ogr
am f
ort
hei
rownuse
4.Appli
cati
onPr ogrammer/ dev
eloperandSystemsAnaly
st
- System analystdet
erminestheuserrequi
rementandhowtheuserwantstovi
ew
thedatabase.
- Theappl i
cationprogrammeri mplementsthesespeci
fi
cat
ionsasprograms;
15
code,test,
debug,documentandmaintaintheappli
cati
onprogram.
- Determinestheinterf
aceonhow t or et
ri
ev e,i
nsert
,updateanddelet
edataint
he
database.
- Theappl i
cati
oncoulduseanyhi ghlevelprogramminglanguageaccor
dingt
o
theavail
abil
it
y,t
hefacil
it
yandtherequi
redser vi
ce.
Workersbehindt heScene
Workersbehi nd theScenear et hosewho wor kto maint
aint hedat abasesy stem
env
ironmentbutwhoar enotact i
v elyi
nterestedinthedatabasecont entsaspar toftheir
dai
lyjob.
- DBMSdesi gnersandi mpl ementers:whodesi gnandi mplementdi f
ferentDBMS
software.
- ToolDev elopers:exper ts who dev el
op software packages thatf acil
itates
database sy stem desi gning and use.Pr otot
ype,simulation,code gener ator
dev el
operscoul dbeanexampl e.Independentsof twarev endorscoul dal sobe
categori
zedi nthisgr oup.
- Oper ators and Mai ntenance Per sonnel:sy st
em admi nist
rat
ors who ar e
responsibleforact uall
yr unningandmai ntai
ningthehardwar eandsof t
war eoft he
databasesy stem andt hei nfor mati
ont echnologyfaci
li
ti
es.
CHAPTERTWO
DATABASESYSTEM ARCHI
TECTURE
I
ntr
oduct
ion
16
The dat abase ar chi tect ur ei saf ramewor kf ordescr i
bi ng dat abase concept s and
speci fyingt hest r
uct ur eofdat abasesy stem.Thear chi tect ur eofDBMSpackageshas
evol vedf rom t heear l
ymonol i
thi csy stems,wher et hewhol eDBMSsof twar epackage
wasonet ight lyi nt egr atedsy stem,t ot hemoder nDBMSpackagest hatar emodul ari n
desi gn,wi thacl i
ent /ser versy st em ar chi tecture.Thi sev ol utionmi rrorst het rendsi n
comput i
ng,wher el ar ge cent r alized mai nfr
ame comput er s ar e bei ng r eplaced by
hundr eds of di stribut ed wor kst at i
ons and per sonal comput ers connect ed v ia
communi cat ionsnet wor kst ov arioust y
pesofser vermachi nes—Webser ver s,dat abase
ser vers, fi
leser v ers,appl icationser ver s,andsoon.
In a basi ccl ient /ser v erDBMS ar chitect ure,t he sy st em f unct i
onal ityi sdi st ri
but ed
bet weent wot y pesofmodul es.Acl ientmodul ei st ypical lydesi gnedsot hatitwi llrun
onauserwor kst ationorper sonalcomput er.Ty pical l
y ,appl icat ionpr ogr amsanduser
i
nt erfacest hataccesst hedat abaser uni nt hecl i
entmodul e.Hence,t hecl ientmodul e
handl esuseri nt er actionandpr ov idest heuser -fri
endl yi nt er f
acessuchasf or ms-or
menu- basedGUI s( gr aphi caluseri nter f
aces) .Theot herki ndofmodul e,cal l
edaser v er
modul e, typi cal lyhandl esdat ast or age, access, sear ch, andot herf unct i
ons.Wedi scuss
cli
ent /ser verar chi tectur esi nmor edet ailinnextSect ion.
Addi tional ly,amaj orai m ofdat abasei st opr ov ideuser swi t hanabst ractv i
ewofdat a,
hidingcer tai ndet ailsofhowdat ai sst oredandmani pul at ed.Si ncedat abasei sashar ed
resour ceseachuser smayr equi readi fferentv i
ewoft hedat a.Tosat isf yt heseneeds,
thear chitect ureofmostcommer cialDBMSsav ail
abl et odayi sbasedont heso- cal l
ed
ANSI -
SPARCAr chitect ur e( Amer i
caNat ionalSt andar dI nst itutionSt andar dPl anni ngand
Requi rementcommi ttee) .
2.1.Schema, Inst ances, andDat abaseSt ate
Thepl ansoft hedat abaseanddat ast or edi nt hedat abasear emosti mpor t
antf oran
organi zat ion, sincedat abasei sdesi gnedt opr ovidei nf ormat iont ot heor gani zat i
on.The
dat ast or edi nt hedat abasechangesr egul arlybutt hepl ansr emai nst aticf orl onger
per i
odsoft i
me.
2.1.1.Schema
Aschemai spl anoft hedat abaset hatgi vet henamesoft heent itiesandat tri
but esand
ther elat i
onshi pamongt hem.Aschemai ncludest hedef i
ni tionoft hedat abasename,
ther ecor dt ypeandt hecomponent st hatmakeupt her ecor ds.Al ternativ ely, i
tisdef ined
asaf rame- wor ki nt owhi cht hev aluesoft hedat aitemsar ef i
t t
ed.Thev al uesf ittedi nt o
thef rame- wor kchangesr egular lybutt hef ormatofschemar emai nst hesame.
Gener all
y ,aschemacanbepar ti
t i
onedi nt ot wocat egor i
es,i .e.,(i)Logi calschemaand
(i
i)Phy sical schema.
(i) Thel ogi calschemai sconcer nedwi t
hex ploi t
ingt hedat ast ructur esof feredby
theDBMSsot hatt heschemabecomesunder standabl et ot hecomput er .Iti s
impor tantaspr ogr amsusei ttoconst ructappl icat ions.
(ii) Thephy sicalschemai sconcer nedwi tht hemanneri nwhi cht heconcept ual
dat abasegetr epr esent edi nt hecomput erasast or eddat abase.I tishi dden
behi ndt hel ogi calschemaandcanusual l
ybemodi f i
edwi thoutaf fectingt he
appl icat ionpr ogr ams.TheDBMS’ spr ovideDDLandDSDLt ospeci fybot ht he
17
l
ogi
cal
andphy
sical
schema.
I
nanydat amodel ,i
tisi
mpor t
anttodisti
nguishbetweent hedescri
pti
onoft hedatabase
andthedat abaseit
self
.Thedescripti
onofadat abasei scall
edt hedatabaseschema,
whichisspeci f
iedduri
ngdatabasedesi gnandi snotexpect edt ochangef r
equently
.
Mostdat amodel shavecer t
ainconv enti
onsfordisplayingschemasasdi agrams.A
di
splay
edschemai scalledaschemadi agram.Thef oll
owingFigureshowsaschema
di
agram forthedatabasewhi chdi
splay sthestr
uctur
eofeachr ecordtypebutnott he
act
ualinstancesofrecords.Wecal leachobjectintheschema—suchasSTUDENTor
COURSE—aschemaconst r
uct.
Aschemadi agr
am displaysonlysomeaspectsofaschema,suchast henamesofr ecord
typesanddat ai
tems,andsomet ypesofconst
raint
s.Otheraspectsarenotspecif
iedinthe
schemadi agram;forex ample,thefol
lowingFigur
eshowsnei therthedatatypeofeach
dataitem,northerel
ationshipsamongt hevar
iousfil
es.Manytypesofconstraint
sarenot
represent
edinschemadi agr
ams.
STUDENT
Name St
udent
_numb Cl
ass Maj
or
er
COURSE
Course_na Cour se_numb Cr edi
t_hour Depar
tmen
me er s t
PREREQUI SITE
Course_numb Pr er
equisi
te_num
er ber
SECTION
Secti
on_identi
fi Course_numb Semest Yea I
nstr
uct
er er er r or
GRADE_ REPORT
Student
_ numb Sect i
on_identi
fi Grade
er er
2.1.2Instances/DatabaseSt ate
Thedat ainthedat abaseatapar ti
cularmomentoft i
mei scall
edani nstanceora
databasest ate.I
nagi veninstance,eachschemaconst ructhasi t
sowncur r
entsetof
i
nst ances.Manyi nstancesordat abasestatescanbeconst r
uctedtocor respondtoa
particul
ardatabaseschema.Ev erytimeweupdat e(i.
e.,insert
,deleteormodi f
y)the
valueofadat ait
em inar ecord,onestateoft hedatabasechangesi ntoanotherstate.
Forexampl e,inthef oll
owingI TEM relat
ionort ableallr ecor
dsar einstancesina
databaseschema
I
TEM
I
tem_ Code I
tem_ Name It
em_ cost
A001 Lapt
op 45000
A002 Pr
int
er 15000
18
Thedat ai nthedat abaseatapar ti
cul
armomenti nt i
mei scal l
edadat abasest at
eor
snapshot .Iti
sal socall
edt hecur
rentsetofoccur rencesorinst ancesint hedatabase.
Inagivendat abasest ate,eachschemaconst ructhasi sowncur
t rentsetofi nst
ances;
forexampl e,theSTUDENTconst ructwil
lcontaint hesetofi ndividualstudententit
ies
(recor
ds)asi tsinstances.Manydatabasestatescanbeconst ructedt ocorrespondtoa
parti
culardatabaseschema.Ev er
ytimewei nsertordeletearecor dorchanget hevalue
ofadat aitem inar ecord,
wechangeonest ateoft hedatabasei ntoanotherst at
e.
Thedi
sti
nct
ionbet
weendatabaseschemaanddatabasest
atei
sveryi
mpor
tant
.When
wedef
ineanewdatabase,
wespecifyi
tsdat
abaseschemaonl
ytot
heDBMS.
Atthispoint,t
hecor r
espondingdatabasest ateist heempt ystatewithnodat a.Weget
theini
ti
alstateoft hedatabasewhent hedat abasei sfi
rstpopulatedorl oadedwi t
hthe
i
niti
aldata.From thenon, everyti
meanupdat eoper at
ionisappliedtot hedatabase,we
getanotherdatabasest ate.Atanypoi ntintime,t hedat abasehasacur rentstat
e.The
DBMSi spar tlyresponsiblef orensuri
ngt hatev erystateoft hedat abasei sav ali
d
stat
e—thati s,ast atethatsat i
sfi
est hest ructureand const rai
ntsspeci fi
ed inthe
schema.Hence,speci fy
ingacor rectschemat ot heDBMSi sext r
emel yimpor t
antand
theschemamustbedesi gnedwi t
hut mostcar e.
TheDBMSst oresthedescripti
onsoft heschemaconstr
uctsandconst r
aint
s—also
cal
ledt hemet a-dat
a—intheDBMScat alogsothatDBMSsof twarecanrefertothe
schemawhenev eri
tneedst o.Theschemai ssometimescal l
ed t
heintensi
on of
database,andadat abasestateiscal
l
edanext ensi
onoftheschema.Thedat ainthe
databaseatanypar t
icul
arpoi
ntinti
meiscalledadat
abaseinst
anceordatabasestat
e.
2.2.Overvi
ewofdat amodels
Adat abasemodeli saconcept ualdescr iptionofhowt hedat abasewor ks.Itdescr i
bes
howt hedatael ement sarestoredint hedat abaseandhowt hedat aispresent edt othe
userandpr ogrammerf oraccess;andt her elationshipbet weendi ffer
enti t
emsi nthe
database.
Adat amodeli sacol l
ecti
onofconcept st hatcanbeusedt odescr i
bethest r
uct ureof
thedatabasei ncludingdatat y
pes,r elationshi psandt heconst raintsthatappl yont he
data.Adatamodel hel
psinunder standingt hemeani ngoft hedat aandensur est hat,we
understand
- Thedat ar equir
ement sofeachuser .
- Theuseofdat aacrossv ari
ousappl i
cat i
ons.
- Thenat ureofdat aindependentofi tsphy sicalrepresent ations.
Adat amodelsuppor tscommuni cat i
onbet weent heuser sanddat abasedesi gner s.The
majoruseofdat amodeli stounder standt hemeani ngoft hedat aandt of acil
it
ate
communi cationaboutt heuserrequi r
ement s.
Manydat amodel shavebeenpr oposed, whi chwecancat egor izeaccor dingtot het ypes
ofconceptst heyuset odescr i
bet hedat abasest ructure.Hi gh- l
ev elorconcept ualdata
model sprovideconcept sthatarecl oset ot hewaymanyuser sper ceivedat a,wher eas
l
ow- l
evelorphy sicaldatamodel spr ov ideconcept st hatdescr ibet hedet ail
sofhow
datai sstoredont hecomput erst oragemedi a,t y
pi call
ymagnet i
cdi sks.Concept s
19
prov idedbyl ow- leveldat amodel sar egener allymeantf orcomput erspeci alist
s, notf or
end user s. Bet ween t hese t wo ext remes i s a cl ass of r epr esent ati
onal( or
i
mpl ement ation)dat amodel s,whi chpr ov i
deconcept st hatmaybeeasi lyunder st ood
byenduser sbutt hatar enott oof arr emov edf rom t hewaydat ai sor ganizedi n
comput erst or age.Repr esent at ionaldat amodel shi demanydet ailsofdat ast orageon
diskbutcanbei mpl ement edonacomput ersy stem di rect l
y .
Concept ualdat amodel suseconcept ssuchasent it
ies, at tri
butes, andr elationshi ps.An
ent i
tyr epr esent sar eal -wor l
dobj ectorconcept ,suchasanempl oyeeorapr ojectf rom
themi niwor ldt hati sdescr ibedi nt hedat abase.Anat tribut erepr esent ssomepr oper t y
ofi nt erestt hatf urtherdescr ibesanent ity,suchast heempl oy ee’snameorsal ary .A
relationshi pamongt woormor eent iti
esr epr esent sanassoci ationamongt heent i
t i
es.
Repr esent ationalori mpl ement at i
ondat amodel sar et hemodel susedmostf requent ly
i
nt radi tionalcommer cialDBMSs.Thesei ncl udet hewi del yusedr elationaldat amodel ,
aswel last heso- cal l
edl egacydat amodel s—t henet wor kandhi erar chicalmodel s—t hat
hav ebeenwi del yusedi nt hepast .Repr esent at i
onaldat amodel sr epresentdat aby
usingr ecor dst r
uct uresandhencear esomet imescal ledr ecor d-baseddat amodel s.
Wecanr egar dt heobj ectdat amodelasanexampl eofanew f ami lyofhi gher -l
ev el
i
mpl ement ationdat amodel st hatar ecl osert oconcept ualdat amodel s.Ast andar df or
objectdat abasescal ledt heODMGobj ectmodelhasbeenpr oposedbyt heObj ectDat a
ManagementGr oup( ODMG) .Obj ectdat amodel sar eal sof requent lyut i
lizedashi gh-
l
ev el concept ual model s, par t
icul arl
yi nt hesof twar eengi neer i
ngdomai n.
Phy si caldat a model s descr i
be how dat ai s st or ed as f i
les i nt he comput erby
repr esent ingi nf ormat ionsuchasr ecor df or mat s,r ecor dor der i
ngs,andaccesspat hs.
Anaccesspat hi sast ruct uret hatmakest hesear chf orpar ti
cul ardat abaser ecor ds
efficient .Ani ndexi sanexampl eofanaccesspat ht hatal lowsdi rectaccesst odat a
usingani ndext er m orakey wor d.I tissi mi lart ot hei ndexatt heendoft hebook, except
thati tmaybeor gani zedi nal inear ,hier archi cal (tr
ee- struct ured) ,orsomeot herf ashi on.
Adat amodel canbet houghtofascompr i
singt hreecomponent s:
i. Ast ruct uralpar t,consi stingofasetofr ulesaccor di
ngt owhi chdat abasescan
beconst ruct ed;
ii. Amani pul at
iv epar t,def iningt het ypesofoper at iont hatar eal l
owedont hedat a
(thisi ncludest heoper at ionst hatar eusedf orupdat i
ngorr etrievingdat af rom
thedat abaseandf orchangi ngt hest ructureoft hedat abase) ;
i
ii. Possi blyasetofi nt egrityconst raints, whi chensur est hatt hedat ai saccur ate.
2.2.
1.Characterist
icsofDat aModel s
Adatamodelmustpossesst hefoll
owingcharacteri
sti
cssot hatt
hebestpossibl
edata
repr
esent
ationcanbeobt ai
ned.
i
) Diagrammat i
cr epr
esentati
onofthedatamodel .
i
i) Simpl i
cit
yindesi gni
ngi.e.,
Dataandt heirrel
ati
onshipscanbeexpressedand
dist
inguishedeasi l
y.
i
ii
) Appl icati
oni ndependent,sothatdi
ff
erentapplicati
onscanshar
eit.
i
v) Dat ar epresentati
onmustbewi t
houtdupl i
cat
ion.
20
v) Bottom- upappr oachmustbef ol l
owed.
vi
) Consi stencyandst r
uct ur ev alidat ionmustbemai nt ained.
2.2.2.Ty pesofDat aModel s
Thev ariousdat amodel scanbedi videdi nt ot hreecat egor i
es, suchas
(i)Recor dBasedDat aModel s.
(ii)Obj ectBasedDat aModel s.
(iii
)Phy sical Dat aModel s.
(i)Recor d Based Dat aModel s:Thesemodel sr epresentdat abyusi ng t her ecord
structur es.Thesemodel sl i
ebet weent heobj ectbaseddat amodel sandt hephy sical
datamodel s.Thesedat amodel scanbef ur thercategor izedint ot hreet y pes:
(a)Hi erarchi cal Dat aModel
(b)Net wor kDat aModel
(c)Rel ational Dat aModel .
(ii
)Obj ectBasedDat aModel s:Thesemodel sar eusedi ndescr ibingt hedat aatt he
l
ogi calanduserv i
ew l ev els.Thesemodel sal l
ow t heuser st oi mpl icitlyspeci fythe
const raint sint hedat a.Thesedat amodel scanbef urthercat egor izedi ntof ourty pes:
(a)Ent it
yRel at i
onshi pModel (ER-Model )
(b)Obj ectOr ientedModel
(c)Semant icDat aModel
(d)Funct i
onal Dat aModel .
( i
ii
)Phy sicalDat aModel s:Thesemodel spr ov i
det heconcept st hatdescr ibest he
detailsofhow t hedat ai sst or edi nt hecomput eral ongwi t ht hei rrecor dst ructures,
accesspat hsand or der ing.Onl yspeci al i
zed orpr ofessionaluser scan uset hese
model s.Thesedat amodel scanbedi vi
dedi ntotwot ypes:a)Uni fyingModel .(b)Fr ame
Memor yModel .
Recor dbasedDat aModel s
Recor dbaseddat amodel sr epr esentdat abyusi ngt her ecor dst ructur es.Thesear e
usedt odescr ibedat aatt heconcept ualv i
ew lev el.Thesear enamedbecauset he
databasei sst ruct uredi naf i
xedf ormatr ecordsofsev eralt ypes.Theuseoff i
xed
l
engt hr ecor ds si mpl if
yt he phy sicall ev eli mplement ati
on oft he dat abase.These
model sl i
ebet weent heobj ectbaseddat amodel sandt hephy sicaldat amodel s.These
model spr ovidet heconcept st hatmaybeunder stoodbyt heenduser s.Thesedat a
model sdonoti mpl ementt hef ull det ailoft hedat ast orageonacomput ersy stem.Thus,
thesemodel sar eusedt ospeci fyov eral llogicalst r
uctureoft hedat abaseandt o
prov i
dehi ghl ev eldescr iptionofi mpl ement ati
on.Thesear egener allyusedi ntraditi
onal
DBMS’ sandar eal soknownas‘ Repr esent ational DataModel s’ .
Thev ariouscat egor i
esofr ecor dbaseddat amodel sar easf ollows:
(i)Hi erarchi cal Dat aModel
(ii)Net wor kDat aModel
(iii
)Rel at i
onal Dat aModel .
(i)Hi erar chicalDat aModel :Hi er archicalDat aModeli soneoft heol destdat abase
model s.The hi erar chicalmodelbecame popul arwi t
ht he i nt roduct ion ofI BM’s
Informat i
onManagementSy stem ( IMS) .
21
Thehi erarchicaldatamodel organizesrecordsinat reestructurei.
e.,hierarchyofparent
andchi l
dr ecordsr elati
onships.Thi smodelempl oyst womai nconcept s:Recor dand
Par entChi ld Relationship.A r ecordis a collection off ieldv alues t hatpr ovi
de
i
nf ormationofanent i
ty.
APar entChi l
dRel ationshiptypei sa1:Nr el
ati
onshi pbetweent wor ecordt ypes.The
recordt ypeofonesi dei scalledt heparentrecordt ypeandt heoneont heNsi deis
calledthechi ldrecordt ype.I
nt ermsoft r
eedat astructure,arecordty pecor respondsto
nodeofat r
eeandr elati
onshipt ypecorr
espondst oedgeoft het r
ee.Themodel r
equi
res
thateachchi ldrecor dcanbel inkedtoonl yonepar entandchi l
dcanonl yber eached
throughi t
spar ent.
Key
boar
d Mouse
Mat
eri
alsset
Fi
g.TheNet
wor
kdat
amodel
(compl
exf
orm)
(i
ii
)Rel ationaldat aModel :TheRel at ionalModeli sconsi der edoneoft hemostpopul ar
development sint hedat abaset echnol ogybecausei tcanbeusedf orrepr esent ingmost
ofther eal wor ldobj ectsandt her el
at ionshi psbet weent hem.
Themai nsi gni fi
canceoft hemodeli st heabsol utesepar ationoft hel ogi calv iew and
thephy si calv i
ew oft hedat a.Thephy si
calv iew inrelationalmodeli si mpl ement ati
on
dependentandnotf urtherdef ined.
Thel ogi calv i
ew ofdat ai nrelati
onalmodeli ssetor ient ed.A r elationalseti san
unorder edgr oupofi t
ems.Thef ieldint hei t
emsar ethecol umns.Thecol umni nat able
havenames.Ther owsar eunor deredandunnamed.Adat abaseconsi st sofoneor
mor etabl espl usacat al oguedescr ibingt hedat abase.
Ther el
at ional model consi stsoft hreecomponent s:
1.Ast ruct uralcomponent —Asetoft ables( alsocal l
edr elat i
ons)andsetofdomai ns
thatdef i
nest hewaydat acanber epr esent ed.
2.Asetofr ulesf ormai ntai ni
ngt hei nt egrit
yoft hedat abase.
3.Amani pul ativecomponentconsi st ingofasetofhi gh-lev el operati
onswhi chactupon
andpr oducewhol etabl es.
Inther elat i
onalmodelt hedat aisr epr esentedi nt hef or m oft abl
eswhi chi sused
i
nterchangeabl ywi tht hewor dRel ation.Eacht ableconsi stsofr owsal soknownas
tupl
es( At upl erepr esent sacol l
ectionofi nformat i
onaboutani t
em, e.
g.,st udentr ecord)
andcol umnal soknownasat tri
butes.( Anat t
ri
buter epresent sthechar act er ist
icsofan
i
tem,e. g. ,St udent ’
sNameandPhoneNo. ).Therear er el at i
onshipsexi st ingbet ween
dif
ferentt abl es.Thi smodeldoesn’ tr equi reanyi nformat i
ont hatspecifi
eshowt hedat a
shouldbest oredphy sical l
y .
Therelat
ionaldatamodeli
sbasedont heconceptofmat
hematcalr
i el
ati
ons.I
nthe
rel
ati
onalmodel,dat
aandrel
ati
onshi
psarerepr edast
esent abl
es,eachofwhichhasa
numberofcolumnswi t
hauni
quename.Forexample,
Ent
it
y:St
udent Ent
it
y:Cour
se
i
d name cour
seno Cour
seno. Cour
se_
tit
le Cr
edi
t_hr
s
123 Chal
tu CoSci232
CoSci232 Dat
abaseSy
stems 4
456 Beka CoSci112
CoSci112 I
ntr
o.t
ocomputer 3
789 Abebe CoSci232
23
Itisimportanttonotethatt
hereisarelat
ionshipbet
weenstudentandcour
se:one
studenttakesmor ethanonecourse.I
tdescr i
bethattheatt
ri
butecour
senointhe
studentrelat
ionisthesameast hecourseno ofthecourserel
ati
onthatwecan
establ
ishthatarel
ati
onshi
pexi
sts.
The maj oradv ant agesofRel ati
onalModelar et hati ti sst ruct urall
yi ndependent,
i
mpr ov ed concept ualsi mpl icity ad- hoc quer y capabi l
ity,its compl et
ef l
exibil
i
tyi n
descr i
bingt her elationshi psbet weent hev ar iousdat aitemsandpower fulDBMS.The
majordi sadv ant ages ofr elat i
onalmodelar e subst ant i
alhar dwar e and sof tware
overheadandf aci li
tatespoordesi gnandi mpl ement at i
on.
ObjectBasedDat aModel s
ObjectBasedDat aModel sar eal soknownasconcept ualmodel susedf ordef i
ning
concept sincl udi ngent ri
es,at tributesandr el ati
onshi psbet weent hem.Thesemodel s
areusedi ndescr i
bingdat aatt hel ogi calanduserv iewl evels.Thesemodel sallowt he
const raintstobespeci f
iedont hedat aexpl ici tlybyt heuser s.
Anent it
yi sadi st i
nctobj ectwhi chhasexi st encei nr ealwor l
d.I twi l
lbei mplement edas
atabl einadat abase.Anat tr
ibut eist hepr oper tyofanent i
ty,inot herwor ds,attr
ibuteis
asingl eat omi cuni tofi nf ormat i
ont hatdescr ibessomet hingabouti tsent i
ty.Itwillbe
i
mpl ement edasacol umnorf ieldi nt hedat abase.Theassoci ati
onsorl i
nksbet ween
thev ariousent i
t i
esi sknownasr elationships.
Therear e4t ypesofobj ectbaseddat amodel s.Thesear e:
(a)Ent ity-relationshi p( E- R)Model
(b)Obj ect -Or i
ent edModel
(c)Semant i
cDat aModel
(d)Funct ional Dat aModel
(a)Ent i
ty -
Rel ationshi p( E-R)Model :TheE- R modeli sahi ghl ev elconcept ualdat a
modeldev elopedbyCheni n1976t of aci
litat edat abasedesi gn.TheE- Rmodeli st he
gener ali
zat i
onofear l
ierav ail
abl ecommer ci almodell i
ket hehi erar chicalandnet work
model .Ital soal l
owst her epr esent at i
onoft hev ariousconst raint saswel last hei
r
rel
ationshi ps.Ther elationshi p bet ween ent ityset si sr epr esent ed byaname.E- R
rel
ationshi pi sof1:1, 1:NorN:Nt y pewhi cht el
lst hemappi ngf r
om oneent i
tysett o
another .E- Rmodeli sshowndi agrammat ical lyusi ngent it
y-relat i
onshi p( E-R)diagrams
whichr epresent st heel ement soft heconcept ualmodelt hatshow t hemeani ngsand
rel
ationshi psbet weent hoseel ement si ndependentofanypar ticularDBMS.Thev arious
feat
ur esofE- Rmodel are:
- E- RModel canbeeasi l
yconv ertedi ntor elat i
ons( tables).
- E- RModel i
susedf orpur poseofgooddat abasedesi gnbydat abasedev eloper.
- I ti s hel pfulas a pr obl em decomposi tion t oolas i tshows ent it
ies and t he
relationshi pbet weent hoseent ities.
- I tisani t
er ativ epr ocess.
- I ti sv erysi mpl eandeasyt ounder standbyv ari
oust ypesofuser s.
Themaj oradvant
agesofE- R modelar
et hatiti
sconceptual
l
ysi mple,hav
ev isual
repr
esentat
ion,an ef
fect
ive communi
cati
on tooland can be i
ntegr
ated wit
ht he
24
rel
at ional dat amodel .
The maj or di sadv ant ages of E- R modelar et hat t her e ar el i
mi ted const rai
nt
repr esent at i
on,l i
mi tedr elationshi pr epr esent ation,nodat amani pul ati
onl anguageand
l
ossofi nfor mat ioncont ent.
(b)Obj ect -
Or i
ent edDat aModel :Obj ect -
or ient eddat amodeli sal ogi caldat amodelt hat
capt ur est hesemant i
csofobj ect ssuppor tedi nanobj ect -
or ient edpr ogr ammi ng.I tis
basedoncol lect i
onofobj ects,at t
r i
but esandr elati
onshi pswhi cht oget herf ormt he
staticpr oper ti
es.I tal so consi st soft hei nt egr it
yr ulesov erobj ectsand dy nami c
proper tiessuchasoper ationsorr ulesdef iningnewdat abasest at es.
Anobj ecti sacol l
ect i
onofdat aandmet hods.Whendi fferentobj ect sofsamet ypear e
grouped t oget hert heyf or m acl ass.Thi smodeli sused basi call
yf ormul ti
medi a
appl icat ions as wel las dat a wi th compl ex r elationshi ps.The obj ectmodeli s
repr esent edgr aphi callywi thobj ectdi agr amscont ai
ni ngobj ectcl asses.Cl assesar e
arrangedi ntohi erar chiesshar i
ngcommonst ruct ureandbehav iorandar eassoci ated
withot hercl asses.
Adv ant agesofObj ect -Or i
ent edDat aModel s
Thev ariousadv antagesofobj ect -orient eddat amodel ar easf ol l
ows:
- Capabi li
tyt o handl ev ariousdat at y pes:Theobj ect -orient eddat abaseshast he
capabi l
ityt ost or ev ar i
oust ypesofdat asuchast ext ,videopi ct ures, voiceset c.
- I mpr ov ed dat a access:Obj ector ient ed dat a model sr epr esentr elationshi ps
expl icitly.Thi simpr ov est hedat aaccess.
- I mpr ov edpr oduct i
v ity:Obj ect -or i
ent eddat amodel spr ov idev ar iousf eat ur essuchas
i
nher itance,pol y mor phism anddy nami cbi ndi ngt hatal low t heuser st ocompose
obj ect s.Thesef eatur esi ncr easet hepr oduct ivityoft hedat abasedev eloper .
- I nt egr at edappl i
cat iondev elopmentsy st em:Obj ect -or i
ent eddat amodeli scapabl e
of combi ning obj ect -
or iented pr ogr ammi ng wi th dat abase t echnol ogy whi ch
pr ov i
desani ntegr at edappl icat iondev el opmentsy st em.
Disadv ant agesofObj ect -
Or ient edDat aModel s
Thev ariousdi sadv ant agesofobj ect -orient eddat amodel sar easf ollows:
- Notsui tabl ef oral lappl i
cat ions: Obj ect -or ient eddat amodel sar eusedwher et her eis
aneedt omanagecompl exr elationshi psamongdat aobj ect s.Theyar egener all
y
sui tedf orappl icat ionssuchase- commer ce,engi neer i
ngandsci enceet c.andnot
foral lappl icat i
ons.
- Nopr eci sedef ini
tion:I ti sdi fficultt odef i
newhatconst itut esanobj ect -orient ed
DBMSsi ncet henamehasbeenappl icabl et owi dev ar ietyofpr oduct s.
- Di ff
icul tt omai ntain:Thedef initionofobj ecti srequi redt obechangedper i
odi cal l
y
andmi grat i
onofexi stingdat abasest oconf irm t ot henew obj ectdef i
nition.I t
creat espr obl emswhenchangi ngobj ectdef i
ni ti
onsandmi gr atingdat abases.
(c) Semant ic Dat a Model s: These model s ar e used t o expr ess gr eater
i
nt erdependenci es among ent ities ofi nt er est.These i nterdependenci es enabl et he
model st or epr esentt hesemant icoft hedat ai nt hedat abase.Thi scl assofdat a
model sar ei nfluencedbyt hewor kdonebyar ti
f i
cialint elligencer esear cher s.Semant i
c
dat amodel sar edev elopedt oor gani zeandr epr esentknowl edgebutnotdat a.Thi st ype
25
ofdat amodel sareabl et oexpr essgreat eri
nterdependenci
esamongent i
ti
esofi nt
er est.
Mai nframedat abasear ei ncreasinglyadopt i
ngsemant i
cdat amodel s.Al so,i t
sgr owt h
usagei sseeni nPC’s.I ncomi ngt i
mesdat abasemanagementsy stemswi llbepar tiall
y
orf ul l
yintell
igent.
(d)Funct i
onalDat aModel :Thef unctionaldat amodeldescr ibest hoseaspect sofa
sy stem concer nedwi tht ransformationofv al
ues- f
uncti
ons,mappi ngs,const rai
ntsand
funct i
onaldependenci es.Thef uncti
onaldat amodeldescr ibest hecomput ationswi thin
asy stem.I tshowshow out putv aluei ncomput ati
onareder ivedf r
om i nputv al ues
wi thoutr egardf ort he or deri n whi ch the values are comput ed.I tal so includes
const rai
nts among v alues.I tconsi sts ofmul t
ipl
e dataf l
ow di agrams.Dat af low
diagr amsshow t hedependenci esbet weenv aluesandcomput ati
onofout putv al ues
from i nputv aluesandf unctions,withoutr egardf orwhent hef unct ionsar eexecut ed.
Tradi t
ionalcomput i
ngconcept ssuchasexpr essiontreesar eexampl esoff unctional
model s.
26
consi st i
ngofl argenumberofonet omanyr elat i
onshi ps.Becauseoft her estri
cti
ont o
onet omanyr elationships,compl exi tyoft r
eest ructur edi agr ams,l ackofdecl arative
quer yingf aci l
it
iesthehi er archicalmodel lostit si mpor tance.
Thenet wor kdat amodeli susedi nt hoseor gani zat ionswhi chusedat abasesconsi sting
ofl argenumberofmanyt omanyr elat i
onshi ps,butduet oi tscompl exnat ureitisal so
notpr ef erred.
Mostoft heDBMSuseobj ector ient eddat amodel li
ngt echni queswhi char eusedby
l
ar ge numberofor gani zations.Forexampl e—Lat estv ersionsofor acle are obj ect
relati
onal hy bri
dsbecauset heysuppor tbot hrel ational andObj ectOr i
entedf eatures.
2.3.Ar chitectureandDat aI ndependence
2.3.1.Thr eeLev elArchitect ure( Thr eeSchemaAr chi t
ect ure)ofDat abaseSy stems
Thear chitecturei saf ramewor kf ordescr i
bingdat abaseconcept sandspeci fyi
ngt he
structur e of dat abase sy stem.The t hree l evelar chitecture was suggest ed by
ANSI / SPARC. The t hr ee-schema ar chitectur e was pr oposed t o hel p achiev e and
visualizet hebasi cdat abaseappr oachorchar act eristics.Thi si sal soknownast he
ANSI / SPARCar chitecture.TheANSI /SPARCar chitect ur eisappl icablet omostmoder n
dat abase sy st
ems.The goaloft he t hree- schema ar chi t
ecture,i ll
ustrated int he
followi ngf igure,ist osepar atet heuserappl i
cat i
onsf rom t hephy sicaldat abase.Her e
dat abasei sdi vi
dedi ntot hreel evelsext ernall ev el,concept uall evelandi nternallevelas
follows
Fi
g.Thr
eel
evel
archi
tect
ureofDBMS
(
i) I nternalLev el:
I
nternalleveldescr i
best heact ualphysicalstorageofdat aorthewayi nwhichthedata
i
s actuallyst ored in memor y
.Thisl ev elis notr elat
ionalbecause dat
ai s st
ored
accordi
ngt ov ariouscodi ngschemesi nsteadoft abularform(intabl
es)
.Thisisthelow
l
evelrepresent ati
onofent i
redatabase.Thei nt
ernalv i
ewi sdescri
bedbymeansofan
i
nternalschema. Thei nternal l
eveli
sconcer nedwi ththefoll
owingaspects:
–St oragespaceal locati
on
–Accesspat hs
–Dat acompr essionandencr y
ptiont echniques
27
–Recor dpl acementet c.
Thei nter nall evelpr ovidescov eraget ot hedat ast ructuresandf il
eorganizationsused
tostor edat aonst oragedev i
ces.
(
ii
) Concept ualLev el:
Theconcept uallev elisal soknownasl ogicall evelwhi chdescribestheov eral llogi
cal
structureofwhol edat abasef oracommuni tyofuser s.Thislevelisrel
ati
onalbecause
datav isible att hisl ev elwi llbe r elationalt ables and oper ators wil
lbe r elati
onal
operat ors.Thi slev elrepr esent sent i
recont ent soft hedat abasei nanabst ractf ormi n
compar isonwi t
hphy sicall ev el.Her econcept ualschemai sdef i
nedwhi chhi dest he
actual phy sical storageandconcent r
at eonr elationalmodel ofdatabase.
(
ii
i) Ext ernalLev el:
Theext er nall eveli sconcer nedwi thi ndivi
dualuser s.Thisl ev
eldescr i
best heact ual
vi
ew ofdat aseenbyi ndiv i
dualuser s.Theext ernalschemai sdef i
nedbyt heDBAf or
everyuser .Ther emai ningpar tofdat abasei shi ddenf rom thatuser.Thismeansuser
canonl yaccessdat aofi tsowni nterest.Inot herwor ds,usercanaccessonl yt hatpart
ofdat abasef orwhi chhe/ shei saut hor i
zedbyDBA.Thi sleveli
sal sorel
ationalorv ery
closet oi t.
DifferentMappi ngsi nThr eeLev elAr chitect ureofDBMS
Thepr ocessoft ransf ormi ngr equest sandr esultsbet weent het hr
eel evel sarecal l
ed
mappi ngs.Thedat abasemanagementsy stem i sr esponsi blef ort hi
smappi ngbet ween
i
nter nal,external andconcept ual schemas.Ther ear et wot ypesofmappi ngs:
1.Concept ual / I
nter nal mappi ng.
2.TheExt er nal /
Concept ual mappi ng.
1.TheConcept ual /I
nt ernal Mappi ng:
Thismappi ngdef inest hecor r
espondenceoroper ati
onsbet weent heconcept ualv i
ew
andt hephy si calv i
ew.I tspeci fieshowt hedat ai sr etri
evedf rom phy si
calst orageand
shownatconcept ual l
ev el andv i
ce- v ersa.I tspeci fieshowconcept ual r
ecordsandf iel
ds
arer epr esent edatt hei nt ernall ev el.Ital soal l
owsanydi fferencesi nent i
tynames,
attr
ibut enamesandt heiror ders, dat at y
peset c.,tober esolved.
2.TheExt er nal/Concept ualMappi ng:
This mappi ng def i
nes t he cor r espondence bet ween t he concept ualv iew and t he
physi calview.I tspeci f i
eshowt hedat aisr etri
ev edf rom concept uallevelandshownat
externall ev elbecause atext er nall evelsome par tofdat abase i shidden f r
om a
particularuserandev ennamesofdat af i
el dsar echangedet c.
Ther e coul d be one mappi ng bet ween concept ualand i nternall eveland sev eral
mappi ngsbet weenext er nalandconcept uall ev el.Thephy sicaldat aindependencei s
achiev edt hroughconcept ual /i
nt er nalmappi ngwhi l
et hel ogicaldat aindependencei s
achiev edt hroughext ernal /concept ualmappi ng.Thei nformat ionaboutt hemappi ng
request samongv ari
ousschemal ev elsar ei ncludedi nt hesy stem cat alogofDBMS.
Whenschemai schangedatsomel evel,theschemaatt henexthi gherlev elremains
unchanged, onlythemappi ngbet weent het wol evelsischanged.
Adv ant agesofThr ee-lev elAr chitect ure
Themot i
vebehi ndt het hr ee-l
ev elar chitect urei st oi solateeachuser ’
sv i
ew oft he
28
database f rom t he way t he dat abase is phy si
call
y st ored orr epr esented.The
adv antagesoft het hreel ev el archi t
ectureareasf oll
ows:
- Eachuseri sabl et oaccesst hesamedat abuthav eadi fferentcust omi zedv iewof
thedat aaspert her equi r ement .
- Thechangest ophy sicalst or ageor ganizati
ondoesnotaf fectt heint ernalstructure
oft hedat abase.e. g.,mov i
ngt hedatabaset oanewst oragedev ice.
- Touset hedat abase, theuseri snoneedt oconcernaboutt hephy sicaldat ast orage
det ail
s.
- Theconcept ualst ruct ur eoft hedat abasecanbechangedbyt heDBA wi thout
aff ectinganyuser .
- Thedat abasest oragest ructur ecanbechangedbyt heDBAwi thoutaf fect
ingt heuser ’
s
v i
ew.
2.3.2.Dat aI ndependence
I
ti sdef inedast hechar act er i
sticsofadat abasesy stem tochanget heschemaatone
l
ev elwi thouthav ingt ochanget heschemaatt henexthi gherl ev el.Itcanal sobe
defined as t he immuni tyoft he appl i
cation programs t o change i nt he phy sical
represent ationandaccesst echni quesoft hedat abase.Theabov edef initi
onsay st hat
theappl icationpr ogr amsdonotdependonanypar ti
cularphy si
calr epr esentationor
accesst echni queoft hedat abase.
TheDBMSachi evedt hedat aindependencebyt heuseoft hree- l
ev elarchi t
ecture.The
datai ndependencei soft wot ypes:
Fi
g.Thet
hreel
evel
archi
tect
ureMappi
ngandDat
aindependence
29
combini
ngoft
wor
ecor
dsi
ntooneorspl
i
tti
nganexi
sti
ngr
ecor
dint
omor
ethanone
recor
ds.
2.
3.3.Cent
ral
izedandCl
ient
/Ser
verAr
chi
tect
uresf
orDBMSs
a)Cent
ral
izedDBMSsAr
chi
tect
ure
Inthist
ypearchit
ecture,allprocessi
ng wasper f
ormed remotel
yont hecomputer
syst
em,andonlydi
splayinformationandcontr
olsweresentfr
om thecent
ralcomput
er
tothedi
splayt
erminalsorclients,whichwereconnect
edtot hecent
ralcomputerv
ia
vari
oust
ypesofcommuni cati
onsnet works.
Cent
rali
zed DBMS archi
tect
ureis a sy
stem in whi
ch allthe DBMS funct
ional
i
ty,
appl
i
cationprogr
am executi
on,anduserint
erf
aceprocessi
ngiscar r
iedoutonone
machine.
b)Basi
cCl
ient
/Ser
verAr
chi
tect
ures
The conceptofcl ient/serverar chit
ect ure assumes an under ly
ing framewor kt hat
consistsofmanyPCsandwor kst
ationsaswel lasasmal l
ernumberofmai nframe
machi nes,connectedv i
aLANsandot hertypesofcomput ernet works.Acl ientinthis
fr
amewor kisty
pical
lyausermachi net hatpr ovi
desuseri nterfacecapabi li
ti
esandl ocal
processing.When a cl ientr equires access t o addi t
ionalf uncti
onalit
y— such as
databaseaccess—t hatdoesnotexi statt hatmachi ne,itconnect stoaser verthat
providest heneededf unctionali
ty.Aser verisasy stem cont ainingbothhar dwareand
softwar ethatcanpr ovideser vi
cest ot hecl i
entmachi nes,suchasf i
l
eaccess,pr i
nti
ng,
archivi
ng,ordat abaseaccess.I ngener al,somemachi nesi nstallonlycl i
entsof t
ware,
othersonl yserversoftwar e,andst i
l
lot hersmayi ncludebot hcl i
entandser versoftware
Howev er,itismorecommont hatclientandser v
ersof twareusual l
yr unonsepar ate
machi nes.
Two maint ypes ofbasic DBMS ar
chit
ectur
es wer
e cr
eat
ed on t
his under
lyi
ng
cl
ient
/ser
verf
ramework:t
wo-ti
erandt
hree-
ti
er.
i
. Two-
TierCl
ient
/Ser
verAr
chi
tect
uresf
orDBMSs
One-
ti
erAr
chi
tect
ure:
ThesimplestofDat
abaseArchit
ectur
eare1t i
erwheretheCli
ent,Server
,andDatabase
al
lresideonthesamemachi ne.Anyt
imey ouinst
allaDBinyoursy st
em andaccessit
topracti
ceSQLqueriesi
tis1t ierar
chi
tectur
e.Butsucharchi
tectureisrar
elyusedin
producti
on.
Two-
ti
erAr
chi
tect
ure
At
wo-
ti
erar
chi
tect
urei
sadat
abasear
chi
tect
urewher
e
1.Pr
esent
ati
onl
ayerr
unsonacl
i
ent(
PC,
Mobi
l
e,Tabl
et,
etc)
2.Dat
aisst
oredonaSer
ver
.
Anappli
cati
oninterf
acewhi chiscalledODBC (OpenDat abaseConnecti
vi
ty)anAPI
whichal
l
owst hecli
ent-
sideprogram t
ocalltheDBMS.Todaymostoft heDBMSof fers
ODBCdriver
sforthei
rDBMS.2t ierar
chit
ecturepr
ov i
desaddedsecur
it
ytotheDBMSas
i
tisnotexposedt otheenduserdi r
ectl
y.Thisarchi
tect
ureprovi
desDir
ectandfaster
communicati
on.
30
Thedif f
erentapproacht ot wo- ti
ercl i
ent/ ser v
erar chitectur
ewast akenbysomeobj ect
-
ori
entedDBMSs, wher et hesof twar emodul esoft heDBMSwer ediv i
dedbetweencl i
ent
andser verinamor ei ntegratedway .Forexampl e,theser verlevelmayi ncl
udet hepart
oft heDBMS sof twar er esponsi bleforhandl i
ngdat ast orageondi skpages,l ocal
concurrencycontrolandr ecov ery,bufferingandcachi ngofdi skpages,andot hersuch
functi
ons.Meanwhi l
e,t hecl ientl evelmayhandl et heuseri nterface;dat
adi cti
onary
functi
ons;DBMS i nteractions wi th pr ogr ammi ng language compi ler
s;globalquer y
opti
mi zati
on,concurrencycont r
ol,andr ecov eryacr ossmul t
ipleser ver
s;st
ructuri
ngof
complexobj ect
sfrom t hedat ai nthebuf fers; andot hersuchf unctions.
Thear chi
tectur
esdescri
bedher earecal
ledtwo-ti
erarchi
tecturesbecausethesoft
war e
component sar
edist
ri
butedov ertwosystems:cli
entandserver.Theadv ant
agesofthis
archi
tectureareit
ssi mpli
cit
yandseaml esscompat i
bil
i
tywi thexisti
ngsystems.The
emergenceoft heWebchangedt herol
esofclientsandservers,l
eadingtothethr
ee-t
ier
archi
tecture.
Thr
ee-
ti
erAr
chi
tect
ure:
3-
ti
erschemai
sanext
ensi
onoft
he2-
ti
erar
chi
tect
ure.3-
ti
erar
chi
tect
urehasf
oll
owi
ng
l
ayer
s
1.Pr
esent
ati
onl
ayer(
yourPC,
Tabl
et,
Mobi
l
e,et
c.)
2.Appl
i
cat
ionl
ayer(
ser
ver
)
3.Dat
abaseSer
ver
ThisDBMSar chitect
urecontai
nsanAppl icati
onl ayerbetweent heuserandt heDBMS,
whi chi sresponsibleforcommunicatingt heuser 'srequesttot heDBMSsy st
em and
sendt heresponsef rom theDBMSt otheuser .Theappl icat
ionl ay
er(busi
nesslogi
c
l
ay er)alsopr ocessesfuncti
onall
ogic,constraint,andr ul
esbef orepassi
ngdatatothe
userordown t ot he DBMS.Thr ee tierar chitect
urei st he mostpopul arDBMS
architectur
e.
Thegoal
ofThr
ee-
ti
erar
chi
tect
urei
s:
- Tosepar
atet
heuserappl
i
cat
ionsandphy
sical
dat
abase
- Pr
oposedt
osuppor
tDBMSchar
act
eri
sti
cs
- Pr
ogr
am-
dat
aindependence
- Suppor
tofmul
ti
plev
iewsoft
hedat
a
i
i. Thr
ee-
Tierandn-
TierAr
chi
tect
uresf
orWebAppl
icat
ions
ManyWebappl i
cati
onsuseanar chitect
ur ecal l
edt het hree-t
ierarchitect
ure,which
adds an intermediatel ay erbet ween t he cl i
entand t he dat abase server.This
i
ntermediat
el ayerormi ddl et i
eriscal l
edt heapplicati
onser verort heWebser ver
,
dependi
ng on t he application.This ser verpl ays an intermediaryr ole by r
unning
appli
cat
ionpr ogramsandst ori
ngbusi nessr ules(procedur esorconst r
aint
s)thatare
usedtoaccessdat af r
om t hedatabaseser v er.I
tcanal soimpr ovedat abasesecuri
tyby
checki
ngacl i
ent’scredenti
al sbeforeforwar dingarequestt othedat abaseserver.
Cl
i
ent
scont
ainGUIi
nter
facesandsomeaddi
ti
onalappl
i
cat
ion-
speci
fi
cbusi
nessr
ules.
31
Theintermedi ateser veraccept sr equest sf r
om t hecl i
ent,pr ocessest her equestand
sendsdat abasequer iesandcommandst ot hedat abaseser ver,andt henact sasa
conduitforpassi ng( par t
ial
l
y)pr ocesseddat afrom thedat abaseser vertot hecl i
ent s,
whereitmaybepr ocessedf urtherandf ilt
eredt obepr esent edt ouser sinGUIf ormat .
Thus,theuseri nterf
ace,appl i
cat i
onr ules,anddat aaccessactast het hr
eet iers.Itis
al
soequi valentlydescr ibedast hepr esent ati
onl ayerdisplay sinformationt ot heuser
and all
ows dat a ent ry.The busi ness l ogicl ayerhandl es i nt
er mediat
er ules and
constr
aintsbef oredat aispassedupt ot heuserordownt ot heDBMS.Thebot tom layer
i
ncludesalldat amanagementser vices.Themi ddlelayercanal soactasaWebser ver,
whichretri
ev esquer yr esult
sfrom t hedat abaseser verandf ormat sthem intody nami c
Webpagest hatar ev i
ewedbyt heWebbr owseratt heclientside.
2.4.Dat abaseLanguageandI nterface
2.4.
1.DBMSLanguages:
DBMS packages pr ov i
de an i ntegrated f eatur e ofabov el anguages i nto a single
l
anguagecal l
edSt ruct uredQuer yLanguage.
- Dat adef initionl anguage( DDL) ,isusedbyt heDBAandbydat abasedesi gnerst o
definebot hschemas.
- St or agedef initi
onl anguage( SDL) ,isusedt ospeci fythei nter nal schema.
- Vi ewdef initionl anguage( VDL) ,tospeci fyuserv iewsandt hei rmappi ngstot heconcept ual
schema.
- Dat aCont r
ol Language( DCL)i susedt ocont rolthesecur ityofdat abase
- Dat amani pul ationl anguage( DML)pr ovidessetofoper ationsl iker etri
eval,
inserti
on,
delet i
on, andmodi ficationoft hedat a.Ther ear etwomai nt y pesofDMLs.
a)Ahi gh- level ornonpr ocedur alDML
- canbeusedoni tsownt ospeci fycompl exdat abaseoper ationsconci selyMany
DBMS
- Hi gh- l
ev elDMLst atement sei t
hert obeent eredi nteract ivelyf r
om adi spl
aymoni tor
ort ermi nal ort obeembeddedi nagener al-
purposepr ogr ammi ngl anguage.
- canspeci fyandr etrievemanyr ecordsi nasi ngleDMLst at ement ;therefor
e,theyar e
calledset -at -a-t
imeorset -or i
ent edDMLs
- decl arat i
vel anguage
b)Al owl evel orpr ocedur alDML
- mustbeembeddedi nagener al-purposepr ogrammi ngl anguage
- r etrieves i ndi vi
dualr ecords orobj ectsf r
om t he dat abase and pr ocesses each
separ at ely
- t or etrieveandpr ocesseachr ecor df rom asetofr ecor ds.Low- levelDMLsar ealso
calledr ecor d- at
-a- ti
meDMLs
Whenev erDMLcommands,whet herhi ghl evelorl ow l evel ,ar eembeddedi nagener al
-
purposepr ogr ammi ngl anguage,t hatl anguagei scal l
edt hehostl anguageandt heDMLi s
call
edt hedat asubl anguage.Ahi gh-levelDMLusedi nast andal onei nteract
ivemanneri s
call
edaquer yl anguage.
2.4.
2.DBMSI nt erfaces
DBMSi nter f
acei sauseri nterfacewhi chal lowsuseri nter f
acet ot hedat abasetoinput
32
quirywi thoutusi ngquer yl anguage.
a)Manubasedi nt erface:I nt hisi nterface,l istofopt i
onscal ledmenusar epresent.
Usi ngmenususerf eelf r
eebecauseoft her ei snoneedt or ememberanysy ntaxof
quer y.
b) For m basedi nter f
ace:Thi si nt erfacedi spl ay safor mt oeachot her .Useri nsertnew
recor di ndat abasebyf il
li
ngandsubmi ttingsuchf orms.
c)Gr aphi caluseri nterf ace:Thi si nterf ace uses di agrammat i
calr epresentati
on of
opt ion.GUIut i
li
zesbot hmenubasedandf or m basedi nt er
face.
d)Nat ur all anguagei nter face:Thi si nter faceacceptr equestwr it
teni nEngl i
shorany
ot herl anguageandat temptt ounder st andt hem.
2.5.Cl assi fi
cat ionofDBMS
Thedat abasesy stemscanbecl assi fi
edi nt ot hr eecategor iesi.e.,
(i
) Accor dingt ot henumberofuser s
(i
i) Accor dingt ot het ypeofuse
(i
ii) Accor dingt odat abasesi tel ocat ions
(
i) Accor dingt ot heNumberofUser s
Accor di ngt ot henumberofuser s, thedat abasesy st
emscanbef ur t
hersubdi vi
dedi nto
twocat egor ies, namel y :
(a)Si ngl e-userdat abasesy stems
(b)Mul tiuserdat abasesy st ems.
(a)Si ngl e- userdat abasesy stems:I nasi ngl euserdat abasesy stem,t hedat abase
resideonaPC–ont hehar ddi sk.Al lt heappl i
cat i
onsr unont hesamePCanddi rectl
y
accesst hedat abase.I nsi ngleuserdat abasesy stems,t heappl i
cationi st heDBMS.A
singl euseraccessest heappl icat ionsand t hebusi nessr ulesar eenf orced i
nt he
appl icat ionsr unni ngonPC
(b)Mul tiuserdat abasesy stems:I namul tiuserdat abasesy stem,manyPC’ sar e
connect edt hr oughaLocalAr eaNet wor k( LAN)andaf il
eser v erst oresacopyoft he
database f i
les.Each PC on t heLAN i sgi ven a v olumenameon t he f i
leser ver
.
Appl icat ionsr unoneachPCt hati sconnect edt otheLANandaccesst hesamesetof
fi
lesont hef ileser v er.Theappl icat i
oni st heDBMSandeachuserr unsacopyoft he
sameappl icat ionand accessest hesamef iles.Theappl icat i
onsmusthandl et he
concur r encycont rol andt hebusi nessr ulesar eenf orcedi nt heappl icat ion.Theexampl e
i
sMS- AccessorOr aclef ilesonaf ileser v er.
Adv ant agesofMul tiuserDat abaseSy stem
Ther ear emanyadv ant agesofmul ti
userdat abasesy stem.Someoft hem ar eas
foll
ows:
- Abi lityt oshar edat aamongv ar ioususer s.
- Costofst or agei snowdi videdamongv ar ioususer s.
- Lowcostsi ncemostcomponent sar enowcommodi tyi tems.
Disadv ant agesofMul tiuserDat abaseSy st em
Themaj ordi sadv ant ageoft hemul tiuserdat abasesy st em i st hati thasal i
miteddat a
shar ingabi li
tyi .
e. ,onl yaf ewuser scanshar et hedat aatmost .
(i
i).Accor dingt ot heTy peofUse
33
Accor dingt ot het y peofuse, thedat abasesy stemscanbef urthersubdi vi
dedi ntot hr ee
cat egor ies, namel y :
(a)Pr oduct ionorTr ansact ional Dat abaseSy stems
(b)Deci sionSuppor tDat abaseSy stems
(c)Dat aWar ehouses.
(a)Pr oduct ionorTr ansact i
onalDat abaseSy stems:Thepr oduct iondat abasesy st ems
areusedf ormanagementofsuppl ychai nandf ort racki ngpr oduct ionofi temsi n
fact ories,i nv ent or i
es ofi tems i n war ehouses/ st or es and or der sf ori t
ems.The
transact ionaldat abasesy stemsar eusedf orpur chasesoncr edi tcar dsandgener at i
on
ofmont hlyst at ement s.Theyar eal sousedi nBanksf orcust omeri nf or mat ion,account s,
l
oansandbanki ngt ransact ions.
(b)Deci sion Suppor tDat abase Sy stems:Deci sion suppor tdat abase sy stems ar e
i
nt eract iv e,comput er-basedsy stemst hatai duser si nj udgmentandchoi ceact ivities.
Theypr ov idedat ast or ageandr et riev albutenhancet het radi tionali nformat i
onaccess
andr et riev alf unct i
onswi thsuppor tf ormodelbui ldi ngandmodelbasedr easoni ng.
Theysuppor tf r ami ng,model li
ngandpr obl em sol v i
ng.Ty picalappl icationar easof
DSS’ sar emanagementandpl anni ngi nbusi ness,heal thcar e,mi litaryandanyar eai n
whi chmanagementwi llencount ercompl exdeci si onsi tuat i
ons.DSS’ sar egener al l
y
used f orst rat egi c and t act icaldeci si
ons f aced by upperl ev elmanagementi .e.,
deci sionswi thar easonabl ylowf requencyandhi ghpot ent i
al consequences.
Adat abasesy stem ser vesasadat abankf ortheDSS.I tst oresl ar gequant i
ti
esofdat a
thatar er el ev antt ot hecl assofpr obl emsf orwhi cht heDSShasbeendesi gnedand
prov idesl ogi caldat ast ruct ureswi thwhi cht heuser si nt eract .Thedat abasesy stem i s
capabl eofi nf or mi ngt heusert het ypesofdat at hatar eav ailabl eandhow t ogai n
accesst ot hem.
(c)Dat aWar ehouses:Adat awar ehousei sar elat i
onaldat abasemanagementsy st em
(RDMS)desi gnedspeci f
ical l
yt omeett het ransact i
onpr ocessi ngsy stems.I tcanbe
l
oosel ydef i
nedasanycent ralizeddat ar eposi torywhi chcanbequer iedf orbusi ness
benef i
t.
(i
ii)Accor di ngt oDat abaseSi teLocat i
ons
Accor dingt odat abasesi tel ocat ions,dat abasesy st emscanbef ur t
hersubdi videdi nt o
four :
(a)Cent ral i
zeddat abasesy st ems
(b)Par allel databasesy st ems
(c)Di st r
ibut eddat abasesy st ems
(d)Cl ient /Ser verdat abasesy stems.
(a)Cent ral ized dat abasesy st ems:Thecent ralized dat abasesy stem consi st sofa
singl e pr ocessort oget herwi thi ts associ ated dat a st or age dev ices and ot her
per ipher al s.Dat abasef ilesr esi desonaper sonal comput er( smal lent erpr i
se)orona
mai nfr amecomput er( largeent erpr i
se) .Theappl icat i
onsar er unont hesamePCor
mai nfr ame comput er.Mul tiple user s access t he appl icat ions t hrough si mpl e
termi nal st hathav enopr ocessi ngpoweroft hei rown.Theuseri nterfacei st ext -
modescr eensandt hebusi nessr ulesar eenf or cedi nt heappl i
cat ionsr unningont he
34
mai nf rameorPC.
Adv antagesofCent ralizedDat abaseSy stem
Ther ear emanyadv ant agesofcent ralizeddat abasesy stem someoft hem ar eas
foll
ows:
- Thecont rolov erappl icationsandsecur it
yi sexcel l
ent .
- Thei ncr ement al costperuseri sv er yl ow.
- Thecent rali
zedsy stemsar ehi ghlyr el iableduet opr ov enmai nf r
amet echnol ogy .
- Manyf unct ionssuchasquer y,backup, updat eet c., areeasi ert oaccompl i
sh.
Disadv ant agesofCent ral i
zedDat abaseSy st em
Thev ari
ousdi sadv ant agesofcent ralizeddat abasesy st em ar easf ollows:
- The user s ar e notabl et o ef f ect ively mani pul at e dat a out side ofst andar d
appl icat ions.
- Thesy stem i snotabl et oef fectivel yser veadv anceuseri nt erfaces.
- Thef ailureofcent ralcomput erbl ocksev eryuserf rom usi ngt hesy st em unt i
lt he
sy stem comesback.
- Thecommuni cat ioncost sf rom t het ermi nalt ot hecent r
alcomput eri samat terof
concer n.
(b)Par al l
eldat abasesy st ems:Apar al leldat abasesy stem canbedef inedasadat abase
system i mpl ement ed on a t ight lycoupl ed mul tiprocessororon a l ooselycoupl ed
mul ti
processor .Par al leldat abasesy st emsl inkmul ti
pl esmal lermachi nest oachi evet he
samet hr oughputasasi nglel ar germachi ne,of tenwi t
hgr eaterscal abi li
t yandr eli
abi l
it
y
than si nglepr ocessordat abasesy st em.Par all
eldat abasesy st emsar eused i nt he
applications t hathav et o quer yext remel yl arge dat abases orhav et o process an
extremel yl argenumberoft ransact i
onspersecond.Ther ear et hr eemai narchitectures
forpar allel databasesy st em.Thesear e
- Shar edmemor yar chitect ur e
- Shar eddi skar chi tect ure
- Shar ednot hi ngar chitect ur e.
Adv antagesofPar allel Dat abaseSy st ems
Ther ear emanyadv ant agesofpar all
el dat abasesy stems.Someoft hesear easfollows:
- Thesear ev er yusef ulint heappl icat ionswher el ar gedat abaseshav etobequer i
ed
orwher eext remel yl argenumberoft ransact ionspersecondhast obepr ocessed.
- Ther esponset imeandt het hroughputi sver yhi gh.
- Thei nput / out putspeedsandpr ocessi ngi sv er yhi gh.
- Theyhav egr eat erscal abi l
ityandr eli
abi li
tythansi ngl epr ocessorsy stem.
Disadv ant agesofPar al l
elDat abaseSy st ems
Thev ari
ousdi sadv ant agesofpar all
el dat abasesy stemsar easf ollows:
- Duet ost ar t-
upcostandst art-
upt ime, theov er allspeedupi sadv er selyaff
ect ed.
- Duet opr ocessesexecut edi npar allel,shar i
ngt her esour ces,asl ow downmay
resul tof fereachnew pr ocessasi tcompet eswi thexi stingpr ocessesf ort he
resour ces.
(c)Di stribut eddat abasesy stems:Adi st ri
but eddat abasesy stem i sadat abasesy stem,
i
nwhi ch,t hedat ai sspr eadacr ossav ar ietyofdi fferentdat abases.Thesear emanaged
35
byav ar i
et yofDBMS’ st hatar er unni ngonv ar i
oust ypesofmachi neshav i
ngdi f
ferent
oper atingsy st ems.Thesemachi nesar ewi del yspr eadandar econnect edt hrought he
communi cat ionnet wor ks.Eachmachi necanhav eisowndat aandappl ications,andcan
accessdat ast or edonot hermachi nes.Thus,eachmachi neact sasaser veraswel las
cli
ent .Thus,di str i
but ed dat abase sy stem i s a combi nat ion ofl ogical l
yi nt err
elated
databases di st ribut ed ov er a comput er net wor k and t he di stri
but ed dat abase
managementsy st em ( DDBMS) .Adi stribut eddat abasesy st em canbehomogeneousor
heter ogeneous.
Adv ant agesofDi st ri
but edDat abaseSy st ems
Thev ar i
ousadv ant agesofdi stri
but eddat abasesy st
emsar easf ollows:
- I mpr ov edshar i
ngabi li
ty over head and bet ter r esponse
- Local aut onomy ti
me
- Av ailabi li
ty - Mor eeconomi cal
- Rel i
abi lity - Di rectuseri nt eraction
- I mpr ov edper for mance - Noasi ngl epoi ntfailure
- Easi erexpansi on - Pr ocessori ndependence
- Reduced communi cat ions
- .
Disadv ant agesofDi stribut edDat abaseSy stems
Thev ar i
ousdi sadv ant agesofdi st ributeddat abasesy stemsar easf ollows:
- Ar chi tect ur al compl exity - Pr obl em ofsecur it
y
- Lackofst andar ds - Hi ghcost
- Lackofpr of essi onal suppor t - Compl exdat abasedesi gn
- Dat ai nt egr itypr oblems
- .
(d)Cl ient /Ser v erDat abaseSy stem:Wi tht hedev elopmentoft echnol ogy,har dwar ecost
becomecheaperandcheaperandmor eper sonalcomput er sar eused.Ther ewasa
changeandent er prisesst ar teduseofcl i
ent -servert echnol ogyi nsteadofcent ral
ized
system.I ncl ient ser
v et echnol ogy ,ther ei saser verwhi chact sasawhol edat abase
managementsy st em andsomecl i
ent sorper sonalcomput erswhi char econnect ed
withser vert hroughanet wor kint erface.
Component sofCl ient -Serv erAr chi tectur e
Ther ear et hreemaj orcomponent sofcl ientser verar chitect ur e:
1.Ser v er 2.Cl ient 3.Net wor kint er f
ace
1.Ser v er:Ser v eri sDBMSi tself.I tconsi stsofDBMSandsuppor tsal lbasi cDBMS
funct i
ons.Ser vercomponent sofDBMSar ei nstalledatser v er.Itact sasmoni torofal l
ofi tscl ient s.I tdi stributeswor k-loadt o ot hercomput er s.Cl i
ent smustobeyt heir
server s.
Funct ionsofSer v er :
- I tsuppor tsal lbasi cDBMSf unct ions.
- Moni toral l hiscl ients.
- Di str i
but ewor k-loadov ercl ient s.
- Sol vepr obl emswhi char enotsol vedbycl i
ents.
36
- Mai nt ainsecur i
tyandpr i
vacy .
- Av oi dingunaut hor izedaccessofdat a.
2.Client s:Cl ientmachi nei saper sonalcomput erorwor kstationwhi chpr ov i
deser vi
ces
tobot hser veranduser s.I tmustobeyhi sser v er.Cl ientcomponent sofDBMSar e
i
nstalledatcl i
entsi te.Cl i
ent sar et aki
ngi nst ruct i
onsf rom ser verandhel pt hem by
taki
ngt hei rl oad.Whenanyuserwantt oexecut eaquer yoncl ient,thecl i
entf irsttake
dataf rom ser v ert henex ecut et hequer yonhi sownhar dwar eandr eturnst her esultt o
theser ver .Asar esul t,ser v eri sfreet odomor ecompl exappl i
cat ions.
3.Net wor kI nt erface:Cl ient sar econnect edt oser verbynet wor kinterface.I tisusef ulin
connect ingt heser veri nt er facewi thuseri nter facesot hatser vercanr unhi sappl ications
overhi scl ient s.
Inthecl ientser verar chi tect ur e,therear emor et hanoneser v
er .Somet i
mes, aser v
eri s
usedasDat abaseSer ver , ot herasAppl i
cationSer ver, otherasBackupSer veret c.
Advant agesofCl ient-Ser v erDat abaseSy stem
- I ti ncr easet heov er allper formanceofDBMS.
- Loadcanbedi st ribut edamongcl i
ent s.
- I tpr ov idesbet teruseri nterface.
- I tisusedt odev elophi ghlycompl exappl icat i
ons.
- Cl ient swi thdi ff er entoper ati
ngsy stemscanbeconnect edwi t
heachot her.
- Si ngl ecopyofDBMSi sshar edandi treducescost .
Disadv ant agesofCl ient -Ser v erDat abaseSy st em
- Net wor ki ser rorpr one.
- I tisaki ndofcent ral i
zedsy stem.I fser veri scr ashedorf ail
ed,ther eisl ossof
dat a.
- Recov er yi st ypi calandaddi t
ionalbur denonDBMSser vertohandl econcur rency
cont rol.
- Pr ogr ammi ngcosti shi gh.
- Thei mpl ement at ioni smor ecompl exsi nceoneneedst odealwi tht hemi ddlewar e
andt henet wor k.
Compar isonbet weenCl ient /
Ser verandDi stribut edDat abaseSy st
em
Client /Ser verDat abaseSy stem Dist ri
but edDat abaseSy stem
1.I nt hi s,di ff
er entpl atf ormsar eof ten 1.I nt his,di fferentpl atf
ormscanbemanaged
diffi
cul tt omanage. easi ly
2. Her e, appl icat ion i s usual ly 2.Her e, appl icati
oni sdistri
but edacr osssi t
es.
distribut edacr osscl ient s
3.I nt hi s dat abase sy stem,whol e 3.Her e,f ailureofonesi t
edoesn’ tbringt he
syst em comes t o a hal ti f server ent iresy stem downassy stem maybeabl et o
crashes. rerout et heonesi te’sr equestt oanot hersi t
e
4.Mai nt enancecosti sl ow. 4.Mai ntenancecosti smuchhi gher
5.Int hissy st em, accesst odat acanbe 5.I nDDSnotonl ydoest heaccesst or eplicate
easi l
ycont rolled. the dat a has t o be cont r
olled atmul ti
ple
37
l
ocati
onsbutalsothenet
workhast
obemade
secur
e.
6.Inthis,new si
tescannotbeadded 6.Inthi
s,newsit
escanbeaddedwithl
i
ttl
eor
easi
ly. noprobl
em
7.Speedofdatabaseaccessi
sgood. 7.Speedofdatabaseaccessi
smuchbett
er.
38
B. adat ast ructure D.anent ity
11.I nformal r elational model terminol ogy ,acol umni scal led_ _____.
A.t upl e C.at tribut e
B.r el ation D.domai n
12. Whi choft hesei snotaf eat ureofHi er ar chical model ?
A.Or gani zest hedat ai ntree-likest r uct ure
B.Par entnodecanhav eanynumberofchi ldnodes
C.Rootnodedoesnothav eanypar ent
D.Chi ldnodecanhav eanynumberofpar entnodes
CHAPTERTHREE
DATABASEMODELI NG
Introduct ion
Dat amodel ing( dat amodel ing)i sthepr ocessofcr eat ingadat amodelf ort hedat at o
best oredi nadat abase.Thi sdat amodel isaconcept ual r
epr esent ationofDat aobj ects,
theassoci ationsbet weendi fferentdat aobj ect s,andt her ules.Dat amodel i
nghel psi n
thev isualr epr esent ationofdat aandenf or cesbusi nessr ules,r egulat or ycompl i
ances,
and gov ernmentpol iciesont hedat a.Dat aModel sensur econsi st encyi nnami ng
conv entions, def aultv alues, semant ics, andsecur i
tywhi leensur ingqual ityoft hedat a.
3.1.TheEnt i
tyRel ationshi p( ER)Model
Theent i
ty-relat ionshi p( E-R)modelwasi nt roducedbyCheni n1976.Hedescr ibedt he
mai n const r
uct soft heE- R modeli .e.,ent ities,r elat i
onshi psand t hei rassoci ated
attributes.TheE- Rmodel cont inuest oev ol v ebutt her ei snoty etast andar dnot ationf or
E-Rmodel i
ng.E- Rmodel i
smai nlyusedf orconcept ual dat amodel ing.
TheE- Rmodeli smai nl yusedf orcommuni cat ionbet weendat abasedesi gner sandend
user s dur i
ng t he anal ysis phase ofdat abase dev el opment .Thi s E- R modeli sa
represent ationoft hest ructureandconst r aint sofadat abaset hati sindependentoft he
DBMSandi tsassoci at eddat amodel t
hatwi llbeusedt oi mpl ementt hedat abase.
In1980’ smanynewdat abaseappl icat i
onsl i
keComput erAi dedManuf act uring( CAM) ,
Comput erAi dedDesi gn( CAD) ,Comput erAi dedSof twar eEngi neer i
ng( CASE) ,Di gi
tal
publ ishing,Wor l
d Wi de Web ( WWW) ,Tel ecommuni cation appl icat ions et c. ,wer e
i
ntroduced.
Thebasi cE- Rmodel ingconcept swer enol ongersuf ficientt or epr esentt her equi rement
oft hese newerand compl ex appl icat ions.Basi c E- R modelwas notcapabl et o
represent addi tional semant ic model ing concept s. Dat abase desi gner s and
pract iti
oner si nt roducedanew modelnamedasEnhancedEnt i
ty-Rel at i
onshi pModel
(EER)whi chi ncl udest hebasi cE- Rmodelconcept swi thaddi tionalsemant icconcept s
l
ike: Speci alizat ion, Gener ali
zat i
onandCat egor izat i
on.
TheEnt i
ty-Rel at i
onshi p( ER)modeli sahi gh- lev elconcept ualdat amodelt hatf aci l
itat
es
databasedesi gn.A concept ualdat amodeli sasetofconcept st hatdescr ibet he
struct ureofadat abaseandt heassoci at edr et r
iev alandupdat et ransact ionsi nt he
database.Themai npur posef ordev el opi ngahi gh- lev eldat amodeli st osuppor ta
39
user’sper ceptionofdat a,andconcealt hemor etechni calaspect sassoci at
edwi th
databasedesi gn.Fur t
hermore,aconcept ualdat amodeli si ndependentoft hepart
icular
DBMSandhar dwareplatf
ormt hatisusedt oimpl ementt hedat abase
Concept ualmodel ingi sav eryi mportantphasei ndesi gningasuccessf uldatabase
applicat
ion.Thet erm databaseappl icati
onr eferstoapar ti
culardat abaseandt he
associatedpr ogramst hati
mpl ementt hedat abasequer iesandupdat es.
Themodel ingconcept softheEnt i
ty-
Rel at
ionshi p(ER)model ,whi chisapopul arhi gh-
l
ev elconcept ualdat a modelwi llbe descr ibed.Thismodeland i tsv ari
ati
onsar e
frequentlyusedf ortheconcept ualdesignofdat abaseappl i
cati
ons, andmanydat abase
designtool sempl oyitsconcept s.Andal sot hedi agr
ammat i
cnot ati
onassoci atedwi th
theERmodel , knownasERdi agrams.
40
model —such as t he r elationalor t he obj ect-
relationaldat abase model —so t he
concept ual schema i st ransformed f r
om t he hi gh-level dat a model i nt
o t he
i
mpl ement ati
ondat amodel .Thisst epi scalledlogicaldesi gnordat amodelmappi ng;
i
tsr esul ti
sadat abaseschemai nthei mpl ementationdat amodeloft heDBMS.Dat a
model mappi ngisof tenaut omat edorsemi -
aut omatedwi t
hint hedat abasedesi gntools.
Thel astst episthephy sicaldesi gnphase, duringwhi cht hei nternalstoragestructures,
fil
e or ganizati
ons,i ndexes,access pat hs,and phy sicaldesi gn par amet er
sf ort he
databasef il
esarespeci fied.I nparallelwi t
ht heseact ivit
ies,appl i
cationpr ogramsar e
designedandi mplement edasdat abaset r
ansactionscor respondi ngt ot hehighl evel
transact i
onspecifications.
Gener ally,
ast hedescr ipti
ont hehighl eveldesignofdat abase, theEnt it
yRel at
ionship(E
-R)Modeli susedt or epresentconcept ualviewoft hedat abasewhi chi ncl
udesEnt iti
es,
At t
ri
but es,Relati
onshi psandConst raintsbasedont heor gani zati
onalanduserdat a
requirement s(i
.etheERmodel describesdat aasent iti
es, r
elationships,andat tr
ibutes)
42
Non-keyattr
ibut
es.
TypesofKey s
Therearemanykey sthatareusedinthedi
ffer
enttables.Theseareasf
oll
ows:
1.SuperKey: Asuperkeyisasetofcoll
ect
ionofoneormor ethanoneat
tr
ibut
est
hat
canidenti
fydatauniquel
y.Anyenti
tysethasmor ethanonesuperkey
Ex.Inent i
tysetEmpl oyee,showni nFigur eSuperKey sare( I
D,Name, Sal
ary ,Reg.No.
)
,(I
D,Name, Reg.No.)and( I
D)etc.Allcombi nati
onscani dentif
ydatauniquely .
Candidat eKey: Themi nimal superkeyisknownascandi datekey.Considerasuperkey
andthent akeallofitspr opersubsets.Ifnooneoft hepr opersubsetsaresuperkey .
Thenthi ssuperkeyist akenascandi datekey .Ex.IDandReg.No.ar ecandi datekey
Candidatekeyi sanat t
ributeorsetofat tri
butest hatuni quelyidenti
fi
esindividual
occurrencesofanent i
tyt y
pe.CandidateKeycanal sobeknownasKeyAt t
ribute.
Exampl e:Findallpossi
bl ecandidatekey sforthef ollowingr el
ationbasedoni t
scurr
ent
tupl
es:
f
ig.Rel
ati
onshi
p(Bi
nar
y)
Her e,Empl oyeeandDepar tmentar etwoent it
ysets.rst andsf orrelat i
onshipbet ween
Empl oyeeandDepar tment .Wor ks_ inisther elati
onshi psetasshowni nFigure.
- Descr i
pti
ve At t
ributes:At tr
ibut
es of any r el
ationshi p set ar e known as
descr i
pti
ve attri
butes.At t
ributes on r el
at i
onships:at tr
ibut es can be assi gned to
relat
ionships.
Degr eeofar el
ati
onship
Itisthet otalnumberofpar t i
cipatingent it
iesi nar elati
onshi p.Ar elationshi
pofdegr ee
twoi scalledbinary.Thenexthi gherbeingt ernary
,quat ernary ,etc.
Car di
nalit
y :Thecardinali
tyofar elati
oni st henumberoft upl esi tcont ains(Numberof
Rows)
Itdeterminest henumberofpossi blerelati
onshi psf oreachpar t
icipatingentity.Themost
common degr ee forr elationships i s binar y and t he car dinalityr at i
os (also call
ed
relati
onshipt ypes)forbi naryr elationshipsar eone- to-
one( 1:1),one- to-many( 1:M),and
many -
to-many( M:M).
44
RoleandRecur siveRel ati
onshipSet
- Rol e:Thef unctionofanyent it
ywhi chi tplaysi nr elationshipseti scal ledt hat
enti
ty’srol e.e.g.,empl oy eeplayst her oleofwor kerinhisdepar tmenti nFi gure.
-Recur sive Rel ationshi p Set:When t he same ent i
ty set s par ti
ci patei n same
rel
ati
onshi psetmor et hanoncewi thdifferentroleseacht i
me,t hent hi
st ypeof
recursiver el
ationshi pseti sknownasRecur siveRelationshi pset .e. g.,consi deran
exampl eofr elationshi psetwor ks_ i
nandt woent i
tysetst udentandcol lege.Ast udent
whoat tendsweekendcl assesi ncol legeasst udentmayal sobel ectur eri nthatcol l
ege.
Thent hisper sonpl ay stwor oles( student,facult
y)insamer elati
onshi psetwor k_in.
Mappi ngConst raints
Therear ecer t ainconst rai
ntsi nE- R model .Dat aint hedat abasemustf oll
ow t he
constraints.
Const r
aint sactasr ulest owhi cht hecont entsofdat abasemustconf orm.Ther ear e
two t ypes ofmappi ng const raints :(a)Mappi ng car dinali
ties,( b)Par ti
cipat ion
constraints.
Mappi ngCar dinal i
ties( CardinalityRat i
os)
Itspecifiest henumberofent it
iesofanent it
ysett hatar eassoci atedwi t
hent itiesof
anotherent i
tysett hroughar elationshi
pset .Mappi ngCar di
nal i
tiesar ehel pfuli n
describingbi nar yrelationshipset s.
Twoent itysetsXandYhav i
ngbi nar yrel
ationshipsetRmusthav eoneoft hef ollowi ng
mappi ngcar di
nal it
y:
1.Onet oOne( 1:1):Anent it
yi nXi sassoci atedwi t
hatmostoneent it
yi nYandan
entityinYi sassoci atedwi t
hatmostoneent ityi
nX.
FIG.Onetoonecardi
nali
tyrati
o.
Acountryhasonlyonepr esident
.Anypersonmaybet hepresi
dentofatmostone
count
ry
2.Onet oMany(1:N):Anent it
yinXi
sassociat
edwithanynumberofent
it
iesi
nY.
Anentit
yinYisassoci
atedwi t
hatmostoneent
ityi
nX.
Amanagerhasmanyempl
oyeesunderi
tbutanempl
oyeewor
ksunderonl
yone
manager
.
45
3.Manyt oOne(N:1):Anent it
yinXi sassoci
atedwithatmostoneent
it
yinY.An
ent
ityi
nYisassociatedwithanynumberofentit
iesi
nX.
Eg.Aemployeecanwor konsi ngl
eprojectwhil
eanyproj
ectcanbeassignedto
morethanoneempl oyee.
4.ManytoMany( M :N):Anent it
yinXisassociat
edwithanynumber(
zeroormore)
ofenti
ti
esi
nYandv icever
sa.
46
Rel
ati
onshi
pnot
ati
ons
Recur
siv
erel
ati
onshi
p
o Car
dinal
it
y
One-
to-
one(
1:1)r
elat
ionshi
p
One-
to-
Many(
1:M)r
elat
ionshi
p
Many
-to-
Many (
M:N)
r
elat
ionshi
p
o Part
ici
pat
ion
One-
to-
manymandat
ory
One-
to-
manywi
thopt
ional
forent
it
yAandmandat
oryBpar
ti
cipat
ion
One-
to-
manyr
elat
ionshi
pwi
thopt
ional
par
ti
cipat
ionf
orbot
hent
it
iesAandB.
Associ
ati
veent
it
ies
Gener
ali
zat
ion/
Speci
ali
zat
ion
Exampl
es:
1.Cr
eat
eanE-
Rdi
agr
am hav
ingt
woent
it
yset
s,Cust
omerandI
tem
47
Cardi
nal
i
tyRat
ioismanyt omanybecauseacustomercanbuyanynumberofi
tems
andsameit
em canbepurchasedbymoret
hanonecust
omer.
2. MakeanE-
Rdi agr
am wit
henti
ti
esCust
omer,
LoanandPayment
E.
g.:Rel
ati pManagesbet
onshi weenSTAFFandBRANCH
Themul
ti
pli
cit
yoft
herel
ationshipis:
- Onebranchcanonl yhaveonemanager
- Oneempl oyeecouldmanageei
theroneornobr
anches
Empl
oyee 1.
.1 Manages 0.
.1 Br
anch
One-To-
ManyRelationshi
ps
I
ntheone-t
o-manyrelati
onshi
paloanisassoci
atedwit
hatmostonecustomer
v
ia bor
rower,acustomeri sassoci
atedwithsever
al(incl
udi
ng0)loansvia
bor
rower
E.
g.:Rel
ati pLeadsbet
onshi weenSTAFFandPROJECT
Themul
ti
pli
cit
yoft
her
elat
ionshi
p
- Onest
affmayLeadoneormor
epr
oject
(s)
49
- Onepr
ojecti
sLeadbyonest
aff
Empl
oyee 11 Leads 0
..
* Pr
oject
Many
-To-ManyRelat
ionshi
p
- Acust omerisassoci
atedwit
hseveral(
possi
bly0)l
oansv
iabor
rower
- Al oanisassoci
atedwithsev
eral
(possi
bly0)cust
omersv
iabor
rower
E.
g.:Rel
ati pTeachesbet
onshi weenI
NSTRUCTORandCOURSE
Themul
ti
pli
cityoftherelat
ionshi
p
- OneInstructorTeachesoneormor
eCour
se(
s)
I
nst
ruct
or
0
..
* Teaches 1
..
* Cour
se
- OneCour
seThoughtbyZer
oormor
eInst
ruct
or(
s)
Par tici
pationofanEnt itySeti naRel ati
onshi pSet
Par ti
cipati
on const r
ai ntofa r elationshipi si nv olved ini dent if
ying and set t
ing t
he
mandat oryoropt ionalf eat ur
eofanent it
yoccur r
encet otakear olei nar elati
onship.
Ther e ar etwo di stinctpar ticipation const raints wi tht hisr espect ,namel :Tot
y al
Par ti
cipati
onandPar ti
alPar t
icipation
Tot alpar t
ici
pat ion: ev eryt uplei nt heent i
tyorr elati
onpar ticipatesi natl eastone
relati
onshipbyt aki ngar ole.Thi smeans,ev eryt uplei nar elati
onwi llbeattachedwi t
h
atl eastoneot hert upl e.Theent itywi tht otalpar ti
cipat
ioni nar elati
onshipwi llbe
connect edt other elat i
onshi pusi ngadoubl eli
ne.
Par ti
alpar ti
cipat i
on: somet upl ei nt heent it
yorr elati
onmaynotpar ti
cipat einthe
relati
onship.Thi smeans,t herei satl eastonet uplef rom thatRel ationnott akingany
roleint hatspeci fi
cr elationship.Theent i
tywi thpar tialparti
cipationi nar el
ationshipwi l
l
beconnect edt ot her elationshipusi ngasi ngleline.
E.g. 1: Par tici
pat ion of EMPLOYEE i n “ belongs t o” r elati
onshi p wi th
DEPARTMENTi st otal sinceev eryempl oyeeshoul dbel ongt oadepar tment .
Par ti
cipati
onofDEPARTMENTi n“ belongst o”r elationshipwi thEMPLOYEEi s
total
since
Empl oyee BelongsTo Depar tment
ever y
50
depar
tmentshoul
dhav
emor
ethanoneempl
oyee.
E.
g.2:Par
ti
cipati
onofEMPLOYEEin“ manages”r
elat
ionshi
pwit
hDEPARTMENT,
i
sparti
alparti
ci
pati
onsincenotallemployeesaremanagers.Part
ici
pati
onof
DEPARTMENTi n“ Manages”r
elat
ionshi
pwi t
hEMPLOYEEi stot
alsinceever
y
Empl
oyee Manages Depar
tment
depar
tmentshoul
dhav
eamanager
.
Exampl e1:Buil
danERDi agr
am fort
hefol
lowingi nformation:
Ast udentrecordmanagementsy st
em willhav ethef ol
l
owingt wobasi cdataobject
categori
eswiththeirownf eatur
esorproperti
es:St udentswillhaveanI d,Name,Dept,
Age, GPAandCour sewillhaveanId,Name, CreditHour s.Whenev erastudentenrol
lin
acour seinaspecificAcademi cYearandSemest er,theStudentwi l
lhaveagr adefor
thecourse
Name Dept DoB I
d Name Cr
edi
t
I
d Gpa
St
udent
s Cour
se
Age
Enr
oll
ed_
In Semest
er
Academi
c
Yea
r
Gr
ade
Example2:BuildanERDi agram f
orthefol
lowingi
nfor
mat i
on:
APer sonnelr
ecordmanagementsy stem wil
lhavethefol
lowingtwobasicdataobj
ect
categori
eswiththeirownf eatur
esorpropert
ies:Empl
oyeewi l
lhaveanId,Name,DoB,
Age,TelandDepar tmentwi l
lhaveanI d,Name,Locati
on.Whenev eranEmployeeis
assignedinoneDepar tment,thedurati
onofhi sstayint herespect
ivedepar
tment
shouldberegi
stered.
Gui
del
inesfordrawinganEnti
ty-
Relati
onshipDiagram
Entit
yDiscovery
Describeatt
ri
butesandselectanidenti
fi
erforeachoft
heent
it
ies
Identi
fyrel
ati
onshi
psbetweent heselect
edentit
ies
51
Sket
chanE- Rdiagram,addingthedegreeofeachrelat
ionship
Decomposeanymany -t
o-manyr el
ati
onshi
p,al
locat
ingattri
butesandani
dent
if
ier
toanynewent it
iesfor
med
Avoi
dr edundancy.
Limi
ttheuseofweakent i
tyset
s.
Fig.Super cl
ass/subclassrel
ati
onshi
p.
Speci al
izati
on:includes subgroupi
ng ofent i
ti
es withi
n an ent
it
ysethav i
ng some
disti
nctnat uret henot herenti
ti
es.Ifdeepi nfor
mat i
onisneededthengo t owards
speciali
zat i
on.I
not herwor dsSpecial
izat
ionisapr ocessbywhichanyexist
ingentit
y
setisdi videdintosmal l
erent
itysetsaccordi
ngt othedist
inctordi
ff
erentnatur
eof
entit
ies.
53
Eg. Per soni sanent itysetofal lpeopl ewhobel ongst obank.Fur therPer soni s
classi fiedi nt oEmpl oy eesandCust omer sofbank.So,Per sonent i
tyseti sdi videdi nto
Empl oy eeent itysetandCust omerent it
yset .Empl oyeesar ef urthercl assi f
iedi ntot wo
cat egor iesf ullt i
meempl oy eesandpar ttimeempl oyeesandsoon.Cust omer sar eal so
classi fiedi ntoI nv est orsandBor r
ower sandsoon.
Gener al i
zat ion:i tisapr ocessbywhi cht woormor eent i
tyset scanbecombi nedi ntoa
singleent itysetbydet er mi ningsi mi l
arit
iesbet weent heent i
ti
es.I tsanabst r actv i
ewof
anyEnt er pr i
se.Gener alizat i
onpr oceedsf rom ther eorganizat i
ont hatanumberofent it
y
set sshar esomecommonf eat ures.I fanabst r
actv i
ewofi nf ormat ioni sneededt hengo
towar dsgener alizat ion.
Exampl e:I nvest orandBor rowerar et woent i
tyset s.Theyhav ecommonf eat uret hat
bot har eCust omeroft heBank.Si milarly,Empl oy eeent i
tysetandCust omerent ityset
canbecombi nedi nt oPer sonent ityset .
Inher itance:Speci ali
zat ionandgener al
izat i
onl eadst oat tri
but ei nheritancebet ween
higherl ev elent itysetandl owerl ev elent ityset .Inher i
tancei sapr ocessbywhi chl ower
l
ev elent ityseti nher its( ort aken)somepr oper ti
esofi tshigherl ev elentityset .Eg.Her e
ent i
tyset sEmpl oy eeandCust omeri nher i
tsat tributesPer son_ ID,Name,Addr ess,Age
from Per sonent i
tyset .
Aggr egat ionandAssoci at ion
Aggr egat ioni sanabst ract ionpr ocessi nwhi char el
ati
onshi pseti sconsi der edas
higherl ev el ent ityset .
Consi deranexampl eoft ernar yrelat i
onshi phav ingt hreeent ityset sEmpl oyee, Joband
Branchwi thr elat i
onshi psetwor ks- onasshowni npr evious.Thei nfor mat ionabout
Manager sonempl oy ees,manager sofpar t
icularj obsandofdi fferentbr anchescanbe
takeneasi ly.
Speci alizat ionandGener alizat i
onConst raints
Thef ollowi ngconst raintsar eappl iedonspeci al
izati
onandgener ali
zat iont ocapt ure
i
mpor tantbusi nessr ulesoft her elat i
onshi psi nanent erpr i
se.Ther ear et wot ypesof
const raint s:
1.Par ticipat i
onConst raint s: I
tt ellst hepar ti
cipat i
onofent i
tyseti nr elationshi pset s.
Ther ear et wot ypesofpar ti
ci pat i
ons.
- Par tialpar ticipat i
on:I fonl ysomeent i
tiesf r
om ent i
tysetEi spar ticipat edi n
relationshi psi nsetRt heni ti sknownasPar t
ial parti
cipation.
- Tot alpar ticipation:I fev eryent it
yf rom ent itysetEi spar ticipatedwi t hatl east
oner elat ioni nr elationshi psetRt heni tisknownasTot alpar ticipat i
on.
- Her eCust omerandLoanar et woent ityset sandRel ationshi pseti sBor rower .
- Ev er ycust omermayormaynott aket heLoansoCust omerent i
tyseti spar t
iall
y
par ticipat ed.
- Butev eryl oani sconcer nedwi thatl eastonecust omerofbank.SoLoanent it
y
seti st ot al l
ypar ticipat e
54
2.Di sjointConst raints :Di sj
ointconst rai
nts descr ibe t he r elationshi p bet ween
member sofdi ff
erentsubcl asses.Accor dingt oDi sj
ointconst rainti fthesubcl assesofa
specialization/ generalizat i
onar edisjointt henanent itycanbeamemberofonl yone
subclassoft hatspeci ali
zat ion/ generalization.Eg.Subcl assesFul lTi meEmpl oyeeand
PartTi meEmpl oyeeofsuper classEmpl oy ee( di
scussedear lierthatasubcl assmaybe
furt
hercat egor i
zed)ar edi sjoi nt.Supposeanyempl oy ee‘ Mar ti
n’wor ksaspar tti
me
empl oyeef orBankt heni tcanonl ybel ongst osubclass‘ Par tTi meEmpl oyee’.
Categor i
zat i
on
Categor izat i
oni samodel ingpr ocessofasi nglesubcl asshav ingr elationshi pwi t
hmor e
thandi stinctsupercl asses.Thesubcl asshav i
ngmor ethanonesuper classi sknownas
categor yandt hepr ocessofdef i
ningacat egor yisknownascat egor ization.
3.2.4.Mappi ngEERmodelt or elati
onal model
1.Reduct ionofSt rongEnt i
tySet sintoTabl es
Forast rongent it
ysetEwi that tri
butesa1, a2, .
..
,an,makeat ablehav i
ngsamenameas
ofent itysetEandhav ingnnumberofcol umnsort abl enamei sequalt oent i
tyset
nameandnumberofcol umnsi sequal tonumberofat tr
ibut es
2.Reduct ionofComposi teAt tr i
butes
Foracomposi teat tr
ibut e,cr eat easepar at ecolumnf oreachcomponentat tr
ibuteor
partsofcomposi teat tr
ibut es.
3.Reduct ionofMul ti
-valuedAt tri
butes
Formul ti-
valuedat t
ributes, makeasepar atet ablewithcol umnsC1whi chr epresentthe
primar ykeyofent i
tysetorr elati
onshi psetandwi thcol umnsC2whi chr epresentthe
mul ti
-valuedat tr
ibutes.Rowsar eequal tot otalnumberofv al
uesoft hatat t
ribute.
4.Reduct ionofWeakEnt itySet s
LetAbet heweakent it
ysetandBbet hest rongent i
tysetonwhi chAdepends.Then, i
t
i
spossi blet omakeat abl ewi tht ablenameasofWeakEnt it
ySethav i
ngcol umnsequal
totheat tri
but esofWeakEnt itysetpl usPr i
mar yKeyoft heSt r
ongEnt itysetonwhi ch
WeakEnt it
ySetdepends.
5.Reduct ionofRel ationshi pSet s
LetRbet her elationshipsetandE1, E2, ..
.,ENbet heent ityset spar ticipatinginR.Make
at ablewi tht ablenameasofRel ationshi pSethav ingcol umnsequalt onumberof
55
attr
ibutesinrelat
ionshipset( descri
pti
veatt
ri
butes)andpr i
mar ykeysofallpart
ici
pati
ng
entit
yset s.
6.Reduct ionofGener al
ization
Ingener ali
zati
ons,higherl evelenti
tysetsandl owerlevelentit
ysetsar econsidered.
Makeat ableforhigherl evelentit
ysetwithalli
tsattr
ibutes.Forlowerlevelentit
yset,
makeat abl
ewi t
hal lit
sat tri
buteswithpri
marykeyat tr
ibutesofitshigherlevelenti
ty
set.
7.Reduct ionofAggr egation
Reductionofaggr egationi ntotablesissimple.Foral lenti
tysets,maket ablesas
discussedear l
ier
.
3.
3.TheRel
ati
onalDat
abaseModel
Int
roduct i
on
Thepr i
nciplesofther el
ati
onal model wer ef i
rstoutl
inedbyDr .E.F.Coddi naJune1970
papercal l
ed"ARel ati
onalModelofDat aforLar geShar edDat aBanks:'I
nthispaper.Dr.
Coddpr oposedt her elat
ionalmodelf ordat abasesy stems.Themor epopul armodel s
usedatt hattimewer ehierarchicalandnet work,orev ensimplef l
atfi
ledatastruct
ures.
Relat
ionaldat abase managementsy stems ( RDBMS)soon became v er
y popular,
especial
lyf ortheireaseofuseandf lexibi
lit
yinst ructure.Inadditi
on,anumberof
i
nnovat i
vev endors,suchasOr acle,
suppl ement edt heRDBMS\ wi
thasui t
eofpower ful
appli
cationdev el
opmentanduserpr oduct s,provi
dingat otalsol
ution.
Earli
erwe saw how t o conv ertan unor gani
zed textdescr i
pti
on ofi nfor
mation
requirementsintoaconceptualdesign,bytheuseofERdi agr
ams.Theadv antageofER
diagramsi sthattheyfor
cey out oidenti
fydatarequi
rement sthatareimpli
cit
lyknown,
butnotexpl i
cit
lywrit
tendowni nt heorigi
naldescri
ption.Her ewewi llseehow t o
conver tthi
sERintoalogicaldesign(thi
swi l
lbedefi
nedbel ow)ofarelat
ionaldat
abase.
Thelogi calmodelisal
socalledaRel ati
onalModel.
3.3.
1.TheRel ati
onal ModelConcept s
Weshal l r
epresentar elat i
onasat abl ewithcolumnsandr ows.Eachcol umnoft he
tabl
ehasaname, orat tr
ibute.Eachr owiscal edat
l uple.
- Domai n:asetofat omi cv aluest hatanat t
ributecant ake
- At tribute:nameofacol umni napar ticul
art abl
e( alldataisst oredintables).Each
att
ributeAi musthav eadomai n,dom( Ai)
.
- Rel ationalSchema: Thedesi gnofonet able,containingthenameoft het abl
e( i
.e.
thenameoft her elation),andt henamesofal lthecol umns, orat t
ri
butes.Eg:
STUDENT(Name, SI D,Age, GPA)
- Degr eeofaRel ation: thenumberofat tri
butesint her el
ation'sschema.
- Tupl e, t,
ofR(A1, A2, A3,…, An) :anORDEREDsetofv al
ues, <v 1,v2,v3,…,vn>,
wher eeachv ii
sav aluef r
om dom(Ai) .
- Rel ationInstance, r(R):asetoft upl
es;thus, r
(R)={t 1,t2,t3,…, t
m}
56
NOTES:
1.Thetuplesinani nst
anceofar el
ati
onar
enotconsideredtobeor der
ed_
_putt
ingthe
rowsinadi f
ferentsequencedoesnotchanget
het able.
2.Oncetheschema, R(A1,A2,A3,…,An)i
sdef
ined,thevalues,
vi,
ineacht
upl
e,t
, must
beorderedast=<v 1,v2,
v3,…,vn>
Pr
opertiesofr elati
ons
Pr
operti
esofdat abaserelationsar e:
- Relationnamei sdisti
nctf rom allotherrel
ati
ons
- eachcel lofr el
ati
oncont ai
nsexact lyoneatomic(singl
e)v
alue
- eachat t
ri
butehasadi stinctname
- valuesofanat tri
butear eall f
rom thesamedomai n
- orderofat t
ri
buteshasnosi gnif
icance
- eacht upleisdisti
nct;therear enodupl i
catetupl
es
- orderoft upleshasnosi gnifi
cance, t
heoret
ical
ly
.
3.3.2.TheRel ati
onalConst r
aintsandRel ationalDat abaseSchemas
Relationalkey s
Ther ear etwokindsofkey sinr elati
ons.Thef i
rstar eidentif
yingkey s:t heprimarykeyi s
themai nconcept ,whil
et woot herkey s–superkeyandcandi dat ekey–ar erelated
concept s.Thesecondki ndi sthef orei
gnkey .
SuperKey s
Asuperkeyi sasetofat tri
buteswhosev aluescanbeusedt ouniquel yidentif
yat uple
withinar el
ati
on.Arelati
onmayhav emor ethanonesuperkey ,butital wayshasatl east
one: thesetofal lat
tri
but esthatmakeupt herelati
on.
Candi dat eKeys
Acandi datekeyi sasuperkeyt hatisminimal ;thatis,thereisnopr opersubsetthati s
i
tselfasuperkey .Arelat i
onmayhav emor ethanonecandi datekey ,andt hedif
ferent
candidat ekey smayhav eadi fferentnumberofat t
ri
but es.Inot herwor ds,youshoul d
notint erpret'
minimal't
omeant hesuperkeywi t
ht hefewestat tri
but es.Acandi datekey
hast wopr opert
ies:
57
(i
)Ineacht upleofR, theval
uesofKuni quelyi
denti
fythatt uple(uniqueness)
(i
i
)Nopr opersubsetofKhast heuniquenesspr oper
ty( i
rr
educi bi
lit
y )
.
Pri
mar yKey
Thepr i
mar ykeyofar elati
oni sacandidatekeyespeci al
lyselectedt obet hekeyf orthe
rel
ation.I n otherwor ds,iti sachoi ce,and t herecan beonl yonecandi datekey
designatedt obet hepr imar ykey.
Relationshipbet weeni dent i
tykeys
Ther elati
onshipbet weenkey s:
Super key⊇Candi dateKey⊇Pr i
maryKey
Foreignkey s
Theat t
ri
bute(s)wi t
hinoner elat
ionthatmat chesacandi datekeyofanot herrel
ati
on.A
rel
ationmayhav esever alf
or ei
gnkeys,associatedwi t
hdiff
erentt argetrelati
ons.
Foreignkey sallow user stol i
nkinformati
oni noner el
ati
ont oi nformat i
oni nanother
rel
ation.Wi thoutFKs, adat abasewoul dbeacol lecti
onofunrelatedt ables.
RelationalModelConst r
ai nts
Int
egr it
yConst raint s:
Eachr elational schemamustsat isfythef ollowingf ourt
ypesofconst raints.
A.Domai nconst r aints
Eachat tributeAimustbeanat omi cv aluef rom dom(Ai )forthatat tr
ibute.
B.KeyConst raints
Super keyofR:Asetofat tri
butes, SK, ofRsucht hatnotwot uplesi nanyv al
idrelati
onal
i
nstance, r(R) , willhav et hesamev aluef orSK.Ther ef
ore,f
oranyt wodi sti
ncttuples,t
1
andt 2inr (R) ,t 1[SK]! =t 2[ SK].
KeyofR:Ami ni mal superkey .Thati s, asuperkey ,K,ofRsucht hatther emov alofANY
att
ributef rom Kwi l
l resulti nasetofat t
ri
but est hatarenotasuperkey .
Exampl eCAR(St ate, LicensePl ateNo, VehicleID,Model ,
Year,Manuf acturer)
Thisschemahast wokey s:
K1={St at e,Li censePl ateNo}
K2={Vehi cleID}
BothK1andK2ar esuper keys.
K3={Vehi cleID, Manuf act urer}i
sasuper key ,butnotakey( Why ? ).
Ifarelationhasmor ethanonekey s,wecansel ectanyone( arbitrari
ly)tobet hepr i
mar y
key.Pr i
mar yKeyat tributesar eunder li
nedi ntheschema:
CAR( State, LicensePl ateNo, VehicleID,Model ,
Year ,Manufacturer)
C.Ent it
yI ntegr ityConst raints
Thepr i
mar ykeyat tri
but e, PK,ofanyr elationalschemaRi nadat abasecannothav enull
val
uesi nanyt uple.I not herwor ds, foreacht ablei naDB, t
heremustbeakey ;foreach
key,ev eryr ow i nt het abl emusthav enon- nullv al
ues.ThisisbecausePKi susedt o
i
dent i
fyt hei ndi vi
dual t
upl es.Mat hemat i
cally,t[
PK]! =NULLforanyt uplet€r (R).
D.Ref erent i
alI nt egr i
tyConst r
aint s
58
Referenti
alintegrit
yconst rai
nt sar eusedt o specif
yt her elati
onshi psbetweent wo
rel
ati
onsi nadat abase.
Considera r eferencing relation,R1,and a r eferenced relati
on,R2.Tupl es i
nt he
ref
erencingrelati
on, R1,hav eat tri
butedFK( cal
ledforeignkeyat t
ributes)thatref
erence
thepr i
marykeyat tr
ibutesoft her ef
erencedr elati
on,R2.At uple,t1,inR1i ssai
dt o
ref
erenceat uple,t2,inR2i ft1[FK]=t 2[PK] .
Ar ef
erenti
alintegrit
yconst raintcanbedi splay
edi nar elati
onaldat abaseschemaasa
dir
ectedar cfrom t her eferenci ng( f
oreign)keyt ot her ef
erenced( pri
mar y)key.For
exampl e
3.3.3.Relati
onalAl gebraOper ati
ons
Relationalalgebrai sa pr ocedurallanguage consistngofasetofoper
i ators.Each
oper atort
akesoneormor er el
ati
onsasi t
si nputandproducesoner elationasi t
sout put.
Thesev enbasicr elat
ionalalgebraoperati
onsar eSelecti
on,Projection,Joining,Uni on,
Intersecti
on,Di f
ferenceandDi visi
on.Itisi mport
anttonot ethattheseoper ationsdo
notal tert
hedat abase.Ther elat
ionproducedbyanoper at
ionisav ai
labletot heuserbut
i
tisnotst oredi nthedat abasebyt heoperation.
Select i
on(alsocal edRest
l ri
cti
on)
TheSELECToper atorselectsalltupl
esfrom somer el
ati
on,sot hatsomeat t
ri
but esin
eacht uplesatisfysomecondi ti
on.Anewr elati
oncontai
ningtheselect edtuplesi sthen
createdasout put .Supposewehav et
herelationSTORES:
Therel
ati
onaloperat
ion:Rl=SELECTSTORESWHERELocati
on='Dubl
in'
sel
ectsal
ltuplesf
orstor
esthatar
elocat
edi
nDubl
i
nandcreat
esthenewrelat
ionR1
whichappearsasfol
lows:
Wecanal
soi
mposecondi
ti
onsonmor
ethanoneat
tr
ibut
e.Forexampl
e,
59
R2=SELECTSTORESWHERELocati
on='Dubl
in'ANDNo-
Bins>100
Thi
soper
ati
onsel
ect
sonl
yonet
uplefr
om ther
elati
on:
Projecti
on
Thepr ojecti
onoperatorconst
ructsanewr elat
ionf r
om someexi
stingrel
ati
onby
selecti
ngonl yspeci
fiedatt
ri
butesoft heexisti
ngr el
ati
onandel
iminati
ngdupli
cat
e
tuplesinthenewl yformedrel
ation.Forexampl e,R3=PROJECTSTORESOVERSt or
e-
ID,Locat i
onr esul
tsin:
Givent hefol
l
owingoper ati
on,R4=PROJECTSTORESOVERLocat ion
Whatwoul dther el
ati
onR4l ookli
ke?
Joining
Joiningisaoperationforcombi ni
ngtworelat
ionsintoasingl
erel
ation.Att
heoutset,i
t
requireschoosi
ngt heattr
ibutestomatchthetuplesineachrel
ati
on.Tuplesi
ndif
ferent
rel
ationsbutwi ththesamev al
ueofmat chi
ngat tr
ibut
esarecombi nedint
oasi ngle
tupleintheoutputrel
ati
on.
Forexampl e,wit
hanewr elati
onITEMS:
…andourpr
evi
ousSTORESr
elat
ion:
i
fwejoinedITEMStoSTORESusingt
heoperator
:R5=JOINSTORES,
ITEMSOVER
St
ore-
ID, t
heresul
ti
ngr
elat
ionR5wouldappearasf
oll
ows:
60
Thisr elati
onresultedf rom aj oiningofI TEMSandSTORESov ert hecommonat tri
but e
Store-ID,i.
e.anytupl esofeachr elationwhi chcontainedt hesamev alueofSt ore-ID
werej oinedtogethert of orm asi ngl et uple.
Joiningr el
ati
onst oget herbasedonequal it
yofv aluesofcommonat tr
ibutesiscal ledan
equijoin.Conditi
onsofj oinmaybeot hert hanequal it
y-wemayal sohav ea‘ great er-
than’ or‘l
ess-t
han’ join.
When dupl icateat t r
ibutesar er emov ed f rom t her esul tofan
equi joi
nt hisiscal ledanat uraljoin.Theexampl eabov eissucha
nat uraljoin-asSt ore- I
Dappear sonl yoncei nt heresult.
Not et hatt herei sof tenaconnect i
onbet weenkey s(primar yand
foreign)andt heat tri
butesov erwhi chaj oini sper for
medi nor der
to amal gamat ei nfor mati
on f r
om mul tipler elated tables i na
dat abase.I nt heabov eexampl e,ITEMS. Stor e_IDisaf oreignkey
reflecting the pr imar ykeySTORE. Store_ID.When we j oi n on
Stor e_ID t he r elationship between t he t abl es is expr essed
expl i
citlyi n t he r esulti
ng out put table. To i l
l
ust r
ate, t he
relationshipbet weent heser el
ationscanbeexpr essedasanE- R
diagr am, shownbel ow.
Union, I
ntersecti
onandDi ff
erence
These ar et he standar d setoper ators.The r equirementf or
carry
ingoutanyoft heseoper at
ionsist hatthet wo oper andrelat
ionsar euni on-
t
h
compat i
ble-i.e.theyhav ethesamenumberofat tr
ibutes(sayn)andt heiat t
ributeof
eachr el
ati
on( i=l ,…,
n)mustbef r
om thesamedomai n( theydonothav et ohav ethe
sameat tr
ibutenames) .
TheUNI ONoper atorbuildsar elati
onconsi sti
ngofal lt
uplesappearinginei therorbot h
oftwospeci f
iedr el
ations.
TheI NTERSECToper atorbuildsar el
ati
onconsi sti
ngofal ltuplesappearingst r
ictl
yin
bothspecifi
edr elati
ons.
TheDI FFERENCEoper atorbuil
dsar el
ati
onconsi st
ingofal lt
uplesappearingi nthef i
rst
,
but not t he second of t wo speci f
ied r el
ati
ons. Thi s may be r epresented
diagrammat i
callyasshownbel ow.
61
Asanexer
cise,
find:C=UNI
ON(
A,B)
,C=I
NTERSTI
ON(
A,B)andC=DI
FFERENCE(
A,B)
.
Divi
sion
I
ni t
ssi mplestfor
m,thisoperat
ionhasabinar
yrel
ati
onR(X,
Y)ast hedi
vi
dendanda
div
isorthatincl
udesY.Theoutputi
saset
,S,,ofval
uesofXsuchthatx€Sift
her
eisa
row (x,
y)inRf oreachyv alueinthedi
vi
sor.Asanexample,supposewehavetwo
rel
ati
onsR6andR7:
Theoper
ati
on:
R8=R6/R7wi
l
lgi
vet
her
esul
t:
Thi
sisbecauseC3istheonl
ycompanyforwhichther
eisarowwithBost
onandNew
Yor
k.Theothercompani
es,C1andC2,donotsati
sfythi
scondi
ti
on.
REVI
EW QUESTI ONS
1.Thedatatypeofval
uesthatappearineachcolumnisrepresent
edby__
_ofpossi
ble
val
ues.
A.range C.product
B.domai n D.f
uncti
on
2.Thedegreeofrel
ati
onisthenumberof_ __
___ofit
srel
ationschema.
A.attr
ibut
es C.t upl
es
B. dat
at y
pes D.r el
ati
onshi
ps
62
3.Thenul lvalueofanat tribut ei ndicat es_ __ ___v alue.
A. zer o C.unknown
B. inf i
nite D.er ror
4.Ther owsofar elat
ion
A. mustbei nspeci f i
edor der
B. maybei nanyor der
C.inascendi ngor derofkey
D.i ndescendi ngor derofkey
5.5.Whi choft hef oll
owi ngconst raintspeci fiest hatnot wodistinctt
uplesinanystate
ofrelational schemacanhav esamev aluesf orsuper keys?
A.Ent i
ty-integr it
y C.Domai n
B.Ref erent ial-i
ntegr it
y D.Key
6.Whi choft hef oll
owi ngconst raintspeci f
iest hatwi thi
neacht uple,
thev alueofeach
att
ributemustbeat omi cv aluef rom somedomai n?
A.Ent i
ty-integr it
y C.Domai n
B.Ref erent ial-i
ntegr it
y D.Key
7.Whi choft hesei snotaf eat ur eofHi erarchi cal model ?
A.Or gani zest hedat ai nt ree- li
kest r ucture
B. Par entnodecanhav eanynumberofchi l
dnodes
C.Rootnodedoesnothav eanypar ent
D.Chi l
dnodecanhav eanynumberofpar entnodes
8.Basi cent i
ty -
relat i
onshi pmodel li
ngandnor mal i
zat i
ontechniquescaptureonlythe
A.Model li
ngofcompl exandunst ruct ureddat at ypes
B.St ruct ureandst at i
cr el ationshi psofst ructureddat a
C.Dy nami candcompl exr elati
onshi pofst ructur eddata
D.Conceptofmodel l
eddat a
9.Whi choft hef ol l
owi ngmi ghtber epresent edwi thamul ti
val
uedat t
ri
bute?
A.Per son’ sname C.Househol dphonenumber s
B.Bankaccountbal ance D.Bookt i
tle.
10.Whichoft hef ol l
owi ngmi ghtber epresent edwi thasingle-
valuedattr
ibute?
A. Per son’ sphonenumber (s)
B.Car ’
scol or
C.Empl oy ee’seducat i
onal backgr ound
D.Per son’ ssoci alsecur i
tynumber
11.Whichoft hef ol l
owi ngt y peofat tri
but ecannotbecr eatedinaDBMS?
A. Der i
ved C.Mul ti
v alued
B. Si mpl e D.Composi te.
12.Ader ivedat tri
but e
A.mustbest or edphy sical lywi thint hedat abase
B. neednotbephy sicallyst oredwi thint hedat abase
C.hasmanyv alues
63
D.mustbebasedont hev alueoft hreeormor eattri
butes
13.
Byrelati
oncardinalit
ywemean
A.numberofi t
emsi narelationshi p
B.numberofr elati
onshipsinwhi chanent i
tycanappear
C.numberofi t
emsi nanent ity
D.numberofent i
tysetswhi chmayber elatedt oagivenentit
y
14.
When t he PK ofone ent itydoes notcont ainthe PK ofa r el
ated ent
ity
,t he
rel
ati
onshipis
A.Mi ssing C.weak
B. strong D.neut ral
15.
Whichoft hefollowingst atement sbestdecr ibest hefuncti
onofanent i
tyrel
ati
on
model ?
A.AnERmodeli sconcernedpr i
mar ilywithal ogi
calv i
ewoft hedataandsecondl y
withthephysicalimplement at
ion
B. AnERmodeli sconcer nedpr imar il
ywi t
haphy sicalimpl
ement at
ionofthedat a
andsecondlywi ththelogi calview
C.AnER modelpr ovi
desav i
ew oft hel ogicoft hedat aandnott hephy si
cal
i
mpl ementati
on
D.AnERmodel i
sent i
rel
yconcer nedwi thmodel l
i
ngt hephysical
implementation
CHAPTERFOUR
FUNCTI
ONALDEPENDENCYANDNORMALI
ZATI
ON
I
ntr
oduct
ion
Normali
zati
on is based on the anal
ysis off uncti
onaldependencies.A f unct
ional
dependencyisaconst raintbetweent wo attri
butesort wo setsofat tr
ibutes.The
purposeofthedatabasedesignist oar
ranget hev ari
ousdat ai
temsi nt
oanor ganized
str
uctur
esot hatitgeneratessetofrelat
ionshipsandst orestheinf
ormationwi thout
anyrepeti
ti
on.Abaddat abasedesignmayr esultintoredundantandspuriousdat aand
i
nformati
on.
Nor malizat
ionisapr ocessf ordecidingwhi chat tributesshouldbegr oupedtogetherin
arelati
on.Itisatooltov alidateandi mproveal ogicaldesign,sothatitsati
sfi
escer tai
n
constraint
sthatavoidredundancyofdat a.Further more,Normalizati
onisdefinedast he
processofdecomposi ngr el
ationswi t
hanomal i
est oproducesmal ler
,well-
organized
rel
ations.Thus,innormal izati
onpr ocess,ar elationwi thredundancycanber ef
inedby
decomposi ngitorreplacingi twithsmallerrelationst hatcontai
nt hesamei nfor
mat ion,
butwi t
houtredundancy .
I
nfor
maldesi
gngui
del
inesf
orr
elat
ionschemas
There ar
efouri
nformalmeasures ofquali
tyforr el
ati
on schema desi
gn.These
measuresar
enotalway
sindependentofoneanother
.TheseFourinf
ormalmeasures
are:
64
a)Meaning(semant i
cs)oft
her el
ati
onattr
ibut
es.
b)Reducingtheredundant(
repeti
ti
ve)val
uesintupl
es.
c)Reducingthenullval
uesintupl
es.
d)Notall
owingthepossibil
i
tyofgenerati
ngspuri
oustupl
es.
a)Meani ngoftherel
ationattr
ibut
es:Descr i
bingt hemeani
ngoft her el
ati
onattri
butes
Gui deli
ne1:Designarel at
ionschemasot hatitiseasytoexpl
aini t
smeani ng.Theat t
ri
but
es
from mul t
ipl
eenti
tyty pesandr elat
ionshipt ypesshouldnotbecombi nedi ntoasi ngl
e
relati
on.Thusar el
ati
onschemat hatcorrespondst ooneentit
yty peoroner /shi
pty pehasa
straightforwardmeaning.
b)Redundanti
nfor
mat
ioni
ntupl
esandupdat
eanomal
ies:Reduci
ngt
her
edundantv
aluesi
n
tupl
es.
Guidel
ine2:Designt
hebaserel
ati
onschemai nsuchawayt hatnoupdat i
onanomalies
(i
nsert
ion,del
eti
onandmodifi
cat
ion)arepresenti
nther el
ati
ons.Ifpresent,not
ethem
andmakesur ethatt
hepr
ogramst hatupdat
ethedatabasewilloper
atecorrectl
y.
c)Nul
lval
uesi
ntupl
es:Reduci
ngt
henul
lval
uesi
ntupl
es
Guidel
ine3:Trytoavoi
d,pl
aci
ngtheattr
ibut
esi
nabaser el
ati
onwhosev aluemay
usuall
ybeNULL.IfNull
’
sareunav
oidabl
e,makesur
ethatappl
yinexcept
ionalcases
onlyandmajor
it
yoft
hetupl
esmusthavesomenotNULLVal
ue.
d)Generat
ionofspur
ioust
upl
es:Notal
l
owi
ngt
hepossi
bil
i
tyofgener
ati
ngspur
ious
tupl
es.
Guidel
ine4:Ther el
ati
onSchemasar edesignedi nsuchawaythattheycanbejoi
ned
withequalit
ycondi ti
onsonat tr
ibutesthatar eei
therprimar
ykeyorf or
eignkey
.This
guaranteesthatnospur ioustupleswi l
lbegener ated.Mat
chi
ngattr
ibut
esinrel
ati
ons
thatarenot( f
oreignkey,pri
mar ykey)combi nati
onsmustbeav oi
ded,becausej
oini
ng
onsuchat tr
ibutesmaypr oducespur i
oustuples.
4.
1Funct
ional
dependenci
es
Functi
onaldependenci
esarether
esul
tofi
nter
rel
ati
onshi
pbet
weenat
tr
ibut
esori
n
betweentupl
esinanyrel
ati
on.
Defi
nit
ion:Inrel
ati
onR,XandYar et hetwosubsetsofthesetofatt
ri
butes,
Yissai
dto
befuncti
onall
ydependentonX i fagi venv al
ueofX ( al
latt
ri
butesinX)uniquel
y
det
erminestheval
ueofY(allat
tri
butesinY).I
tisdenotedbyX→ Y( YdependsuponX)
.
Her
eXi sknownasdeterminantoffuncti
onaldependency.
Exampl
e:Consi
dert
heexampl
eofEmpl
oyeer
elat
ion:
Empl
oyee
EI
D Name Sal
ary
1 Abdisa 15,000
2 Michu 16,000
3 Li
ben 9,
000
65
4 Meti 10,000
5 Abebe 9,
000
InEmployeerel
ati
on,EIDi sprimarykey.Supposey ouwanttoknow thenameand
sal
aryofanyempl oyee.Ifyouhav eEID ofthatempl oy
ee,t
heny oucaneasilyfind
i
nfor
mationofthatemployee.So,NameandSal aryat
tri
but
esdependuponEIDattr
ibute.
Here,Xis(EI
D)andYi s(Name, Sal
ary
).Ther
efore,X(EI
D) Y(Name,Sal
ary)and
Thedet
ermi
nanti
sEI
D.SupposeXhasv
alue3f
rom t
heabov
etabl
e,t
henYhasv
alue(
Liben,
9,
000)
4.
1.1.Funct
ional
DependencyChar
t/Di
agr
am
I
tist hegr aphi
calrepr
esentat
ionoffuncti
ondependenci
esamongattr
ibut
esinany
r
elat
ion.Itiseasi
ertorememberalldependenci
esbymakingFDchar
ts.Thefol
l
owing
f
ourst epsarefol
lowedtodrawFDchart.
1. Fi
ndoutt
hepr
imar
ykeyat
tri
but
es.
2. Makear
ect
angl
eandwr
it
eal
lpr
imar
ykeyat
tr
ibut
esi
nsi
dei
t.
3. Wr
it
eal
lnon-
pri
mekeyat
tri
but
esout
sidet
her
ect
angl
e.
4. Usear
rowst
oshowf
unct
ional
dependencyamongat
tr
ibut
es.
Forexampl
e,todrawt
hefunct
ionaldependencychar
tfort
heabov
eempl
oyeet
abl
e,i
t
canberepr
esent
edasfol
l
ows
Empl
oyee
Name
EI
D
Sal
ary
Exampl
e:Consi
dert
hef
oll
owi
ngr
elat
ion:
Pr
ofessor(
Pfcode,
Dept
,Head,
Time)
.Iti
sassumedt
hat
- Apr
ofessorcanwor
kinmor
ethanoneDepar
tment
.
- Thet
imehespendsi
neachDepar
tmenti
sgi
ven.
- EachDepthasonl
yoneDepar
tmentHead.
Dr
awt
hedependencydi
agr
am f
ort
hegi
venr
elat
ionbyi
dent
if
yingt
hedependenci
es.
Sol
uti
on:
Thef
oll
owi
ngf
igur
eshowst
hecor
respondi
ngdependencydi
agr
am.
Pf
code Ti
me
Dept Head
4.
1.2Ty
pesofFunct
ional
Dependenci
es
Ther
ear
efourmaj
ort
ypesofFD’
s.
66
1.Par
ti
alDependencyandFul
lyFunct
ional
Dependency
- Parti
aldependency:Supposey ouhav emorethanoneat t
ri
butesi
npri
marykey
.
LetAbet henon-pr
imarykeyat tr
ibut
e.IfAisnotdependentuponal
lpr
imar
ykey
att
ri
butesthenpart
ialdependencyexists.
- Full
yfunct
i :LetAbet
onaldependency henon-
primar
ykeyat
tr
ibut
eandvalueofA
i
sdependentuponal lpri
marykeyat
tri
but
es.ThenAissai
dtobef ul
l
yfuncti
onal
dependent
.
Consi
derarel
ati
onstudenthavi
ngpr
imar
ykeyat
tr
ibut
es(
Rol
l
NoandGame)andnon-
pr
imarykeyat
tri
but
es(Grade,
NameandFee)
.
Rol
l
No Name
Gr
ade I
trepr
esents
feeof
part
icul
argame
Game Fee
Fi
g.Part
ialandful
lyfunct
ionaldependencyofst udentr
elati
on.
Asshowni nfigur
eabov e,NameandFeear epar t
iall
ydependentbecausey oucanf i
nd
thenameofst udentbyhi sRollNoandf eeofanygamebynameoft hegame.Gradeis
full
yfunct
ional
lydependentbecausey oucanf i
ndthegr adeofanyst udenti
naparti
cul
ar
gamei fyouknow Rol l
NoandGameoft hatstudent.Parti
aldependencyisduetomor e
thanoneprimarykeyattri
bute.
2.Tr
ansi
ti
veDependencyandNon-
tr
ansi
ti
veDependency
- Transit
ivedependency:Tr ansi
ti
vedependencyi
sduetodependencybetween
non-pri
marykeyattri
butes.Supposei
nar el
ati
onR,X→ Y(YdependsuponX),Y
→ Z( ZdependsuponY) ,t
henX→ Z( ZdependsuponX)
.Theref
ore,
Zissaidto
betransit
ivel
ydependentuponX.
- Non-t
ransi
ti
vedependency:Anyfuncti
onaldependencywhichisnottransit
ivei
s
knownasNon-transi
ti
vedependency.Non-
tr
ansit
ivedependencyexi
stsiftherei
s
nodependencybetweennon-pr
imarykeyatt
ri
butes.
Exampl
e:Considerarel
ati
onstudent(whosef
unct
ionaldependencychar
tisshown
bel
ow)havingprimar
ykeyatt
ri
bute( Rol
l
No)andnon-pri
marykeyat t
ri
butes(
Name,
Semest
er,
Hostel)
.
Name
X Y
Rol
l
No Semest
er
Dependency bet ween
Z non-pr
imarykey
Host
el attr
ibut
es
Fi
g.FDchar
tshowingtr
ansi
ti
veandnon-transi
ti
vedependencyonrel
ati
onstudent
.
Foreachsemest
ertherei
sdif
ferenthost
el.HereHosteli
stransi
ti
vel
ydependentupon
67
Rol
lNo.Semesterofanystudentcanbefi
ndbyhisRoll
No.Host elcanbefi
ndoutby
semesterofst
udent
.Here,
Namei snon-
tr
ansi
ti
vel
ydependentuponRoll
No.
3.Si
ngl
eVal
uedDependencyandMul
ti
val
uedDependency
- Si
ngl
eval
ueddependency
:Inanyrel
ati
onR,ifforaparti
cul
arv
alueofX,Yhas
si
ngl
eval
uet
heniti
sknownassingl
evalueddependency
.
- Mul
ti
val
ueddependency(MVD):I
nanyr
elat
ionR,i
fforaparti
cul
arvalueofX,Yhas
mor
ethanonevalue,t
heniti
sknownasmulti
val
ueddependency
.Itisdenot
edbyX
→→ Y.
Exampl
e:Consi
dert
her
elat
i a)andi
onTeacher( tsFDchar
tshowni
n(b)
.
I
D Teache Cl
ass Day
s
Teacher Cl
ass
r
1Z Al
emu Computer 1
Cl
ass Day
s
2Z John Computer 6
1Z Chal
a El
ectr
oni
cs 3
I
D Teacher
2Z John Mechani
cal 5
3Z Nur Mechani
cal 2
(a) (b)
ThereisMVDbet weenTeacherandClassbecauseat eachercantakemoret hanone
class.Ther
eisanot herMVDbetweenClassandDay sbecauseaclasscanbeonmor e
thanoneday .Thereissi
ngl
evalueddependencybet
weenI DandTeacherbecauseeach
teacherhasauniqueID.
4.Tr
ivi
alDependencyandNon-Tr
ivi
alDependency
- Tri
vialFD:I
nanyrel
ati
onR,X→ Yi stri
vi
ali
fY⊆X(
Yist
hesubsetofX)
.
- Non-
Tri
valFD:I
i nanyr
elat
ionR,
X→Yi
snon-
tr
ivi
ali
fY X(
Yisnott
hesubsetof
X)
Exampl
e:Consi
dert
heSuppl
i
er-
Productr
elat
ion:
S# Ci
ty P# Quanti
ty
1 Harar 1P 100
2 Dir
eDawa 8P 200
3 Adama 3P 50
4 Fi
nfi
nne 5P 75
5 Rohtak 1P 99
6 Mau 5P 105
Her
e,(S#, P#)
:S#i
str
ivi
alFD
S#:
Suppl
i
erI
D
P#:
ProductI
D
Exampl
e.Consi
dert
hegi
venr
elat
ionR:
O P Q
1 2 3
2 1 7
68
2 1 5
7 3 8
Wri
teal
lnon-
tri
vi
alfunct
ional
dependenci
essat
isf
iedbyR.Al
sogi
veanexampl
eofaFD
t
hatdoesnotholdonR.
Sol
.Forf
unct
ional
dependenci
esl
ookatt
hedat
agi
veni
nthet
abl
e.
- TheFDO→ Phol
dsonR,
sincef
oreachv
alueofOt
her
eisasi
ngl
eval
ueofP.
- TheFDO→ QdoesnotholdonR, si
ncei
nthe2ndand3r
drow,
Ohast
hesame
val
ue,
butQhasdi
ff
erentv
alues.
Thenon-
tr
ivi
alf
unct
ional
dependenci
esar
easf
oll
ows:
O→ P,
Q→ O,
Q→ P,
OQ→ P,
PQ→ O,
Q→ OP,
O→ OP,
OQ→ PQ,
OQ→ OPQ,
Q→ OQ,
PQ→ OPQ,
Q→ OPQ,
P→ O,
P→ OP
4.2.Anomali
esinrel
ati
onaldatabase
Therearevari
ousanomali
esorpi tf
all
sinrel
ati
onaldatabase.Vari
ousdependenci
esin
rel
ati
onaldat
abasecausetheseanomal i
es.Anomali
esr ef
erstotheundesi
rabl
eresul
ts
becauseofmodifi
cat
ionofdata.Thevari
ousanomaliesareasfoll
ows:
1.I nser
tionAnomal
y:
Supposey ouwanttoaddnew inf
ormati
oninanyr
elat
ionbutcannotent
ert
hatdat
a
becauseofsomeconstr
aint
s.Thi
sisknownasI
nser
ti
onanomaly.
Inrel
ationEmpl oyee,youcannotaddnew depar tmentFi nanceunl esst her
ei san
employeeinFinancedepar tment.Additi
onoft hi
sinf or
mat i
onv i
olatesEnt i
tyInt
egr i
ty
Rul
e1.( Primar
yKeycannotbeNULL) .Inotherwor ds,wheny oudependonanyot her
i
nformationtoaddnewi nformati
ontheni tl
eadstoinserti
onanomal y.Ifyoutrytoinsert
Dept.
Noofdepar tmentFinancebeforeinser
tingEI
d,anyr ecordcannotbei nsert
ed.
2.Del
eti
onAnomal
y
Thedel et
ionanomalyoccurswheny outryt odel
eteanyexist
inginfor
mat i
onfrom any
rel
ati
onandt hi
scausesdel et
ionofanyot herundesi
rabl
ei nfor
mation. Inr el
ati
on
Employee,ifyoutrytodeletetuplecont aining“
Amina”thisleadst othedelet i
onof
depart
ment“ Sal
es”compl
etely(ther
ei sonlyoneemployeeinsalesdepartment)
.
3.Updat
ionAnomal
y
Theupdati
onanomal yoccurswheny outrytoupdat eanyexisti
ngi nformati
oninany
rel
ati
onandthiscausesinconsi
stencyofdat a.I
nrelati
onEmpl oyee,ifyouchanget he
Dept.
No.ofdepart
mentAccounts.Thiswi l
lcauseinconsist
encyifyouupdat eDept.No.
ofsingl
e employee onl
yot her
wise y ou haveto search al
lempl oy ees worki
ng in
Account
sdepartmentandupdat et hem indivi
dual
l.Not
y e: Wecanupdat eonlyone
t
upl
eatat
ime.
Example:Consi
dert
herelat
ionEmpl
oyeewi
that
tr
ibut
esEI
D,Name,Sal
ary
,Dept
.No,
Dept
.Nameasshowni nt
hefoll
owi
ngtabl
e
Empl
oyee
69
EI
D Name Sal
ary Dept
.No Dept.
Name
1 Chal
aTol a 10,
000 2 Accounts
2 AbelBekel
e 9,
000 2 Accounts
3 AminaAhmed 15,
000 1 Sal
es
6 Fi
nance
5 AlmazBay
u 8,
500 5 Marketi
ng
4.
3.Key
sandfuncti
onaldependenci
es
Akeyorcandidat
ekeyisasetofattr
ibut
esthatuni
quelyidenti
fyarecor
dinarel
ation.Her
e
di
scuss how toidenti
fy di
ff
erentkeys and key at
tr
ibutes,when a setoff uncti
onal
dependenci
esFisgi
ven.
Foragivenrel
ati
onR={ A1,A2,
A3,
………..
,
An}andasetoffunctionaldependenci
esF,Kis
+
asubsetofRandi sknownaskeyofRi fcl
osureofK,i.
e.K → A1, A2,
A3,………..
,Anand
+
nosubsetofKi.e.XsubsetofKsucht
hatX → A1,
A2,A3,
………. .
,An.
Insimplewor dsasubsetKofRi sknownaskeyorcandi
dat
ekeyofRi
fitsat
isf
ies
bot
ht hefol
lowingt
wocondit
ions.
- Thef
ir
stcondi
ti
oni
sthatcl
osur K+cont
eofK, ainsal
ltheat
tr
ibut
esofr
elat
ionR
K+=A1,
( A2,
A3,
……….
.,
An)and
- Thesecondcondi
ti
oni
sthatf
oral
lsubset
sYofK,
( Y+ nev
Y⊆K), ercont
ainsal
l
t
he
At
tri
but
esofr
elat
ionRi
.e.Y+≠A1,
A2,
A3,
……….
.,
An)
.
-I
fonl
yonesubsetofRsat
isf
ytheabov
econdi
ti
ons,
theni
tisknownasPr
imar
yKey
.
-I
fmor
ethanonesubsetofRsat
isf
iest
heabov
econdi
ti
ons,t
hent
hesesubset
sar
e
knownasCandi
dat
eKey
s. I
nthatcaseoneoft
hecandi
dat
ekeyi
sconsi
der
edas
Pri
maryKey
.
- Asuper
setofcandi
dat
eKeyKi
sknownasSuperKey
.
e:Asetofat
Not tri
but
esofr
elat
ionRt
hatdoesnotappearonr
ighthandsi
deofanyFD
i
nFi
saCandi
dat
eKey.
Pri
maryandNon-Pr
imar
ykeyAt tr
ibut
es:Foragivenr
elat
ionR={A1,
A2,
A3,
………..
,An}
,
anat
tri
but
eAisapri
marykeyatt
ri
buteifAisapar
tofanycandi
dat
ekeyofRother
wise
Aisanon-
pri
mar
ykeyatt
ri
bute.
4.
3.Nor
mal
izat
ion
Normalizat
ioni
saprocessbywhichwecandecomposeordivi
deanyrel
ationint
omor e
thanoner elat
iont
or emov eanomal
i
esinr el
ati
onaldat
abase.Iti
sast epbyst ep
processandeachst
epi sknownasNormalForm.Normali
zat
ionisar
eversibl
eprocess.
4.
3.1.Benefit
sofNormali
zati
on
- I tproducessmall
ertabl
eswi
thsmal
l
err
ows,t
hismeansmor
erowsperpage
andhencel essl
ogi
calI
/O.
- I
tisf
ast
eri
nsear
chi
ng,sor
ti
ng,andcr
eat
ingi
ndexes,si
ncet
abl
esar
enar
rower
,
70
andmor
erowsf
itonadat
apage.
- I
tproducesmoretabl
esbyspl
i
tti
ngtheor
igi
nalt
ables.Thusther
ecanbemor
e
cl
ust
eredi
ndexesandhencet
her
eismorefl
exi
bil
i
tyi
ntuningthequeri
es.
- Themor
etabl
esal
l
owbet
teruseofsegment
stocont
rolphy
sicalpl
acementof
dat
a.
- I
ndexsear
chi
ngi
sgener
all
yfast
erasi
ndexest
endt
obenar
rowerandshor
ter
.
- Ther
ear
efeweri
ndexespert
abl
eandhencedat
amodi
fi
cat
ioncommandsar
e
f
ast
er.
-I
tmakest
hedat
abasemor
ecompactb/
cofsmal
lnumberofnul
lval
uesandl
ess
r
edundantdat
a.
- Dat
amodi
fi
cat
ionanomal
i
esar
ereduced.
- I
tisconcept
ual
l
ycl
eanerandeasi
ert
omai
ntai
nandchangeast
heneedschange.
4.
3.2Var
iousNor
malFor
ms
Thedif
fer
entnormalfor
msar easf ol
l
ows.Eachofwhi
chhasi
tsi
mpor
tanceandar
e
moredesi
rabl
ethantheprev
iousone.
4.
3.2.
1Fi
rstNor
malFor
m(1NF)
Ar el
ati
oni sinfir
stnormalfor
mi fdomainofeachatt
ri
butecontai
nsonl
yatomi
cval
ues
ortheintersect
ionofeachr owandcolumncont ai
nsoneandonl yoneval
ue.I
tmeans
at
omi ci
tymustbepr esenti
nrel
ati
on.The1NFdictat
esthefol
lowing:
- F i
eldscontainonlyscal
arval
ues,notar
ray.
- Ther
ecanbeonl
yonev
aluepercol
umn-
rowposi
ti
on(
fi
eld)i
nat
abl
e
- Ther
ecanbenor
epeat
inggr
oups.
- Ar epeati
nggr oupisafiel
dorgr oupoff i
eldswi
thi
nat
abl
ethatoccur
swi
th
mul
ti
plevaluesforasingl
eoccur
renceofthatf
iel
d.
Exampl
e:Consi
dert
her
elat
ionEmpl
oyeewhet
heri
tis1NFNor
mal
i
zedornot
Empl
oyee
EI
D Name Sal
ary Dept
.No Dept.
Nam
e
1 Chal
aTol a 10,
000 2 Accounts
2 AbelBekel
e 9,
000 2 Accounts
3 AminaAhmed 15,
000 1 Sal
es
4 Adem Jemal 12,
00 6 Fi
nance
5 Al
mazBay u 8,
500 5 Marketi
ng
Itisnotinfi
rstnor
malf
orm becauseat
tri
but
eNamei
snotat
omi
c.So,di
vi
deiti
ntotwo
att
ri
butesFir
stNameandLastNamet onormal
i
zet
o1NFasfoll
ows. Now,rel
ati
on
Employeeisi
n1NF.
Empl
oyee
71
EI
D Fi
rstName Last Sal
ary Dept
.No Dept.
Nam
Name e
1 Chal
aTol a Tola 10,
000 2 Accounts
2 AbelBekel
e Bekele 9,
000 2 Accounts
3 AminaAhmed Ahmed 15,
000 1 Sal
es
4 Adem Jemal Jemal 12,
00 6 Fi
nance
5 Al
mazBay u Bayu 8,
500 5 Marketi
ng
Example.Given t
her
elat
ion PART (
Par
t_I
D,Descr
,Pr
ice,Comp_
ID,No)hav
ing t
hef
f
dependenci
es
Par
t_I
D→ Descr
Par
t_I
D→ Pr
ice
Par
t_I
D,Comp_
ID→ No
Det
ermi
net
hehi
ghestnor
mal
for
m oft
hisr
elat
ion.
Sol
.: Thereexi
stsmul
ti
-v
alueattr
ibut
es.Theattr
ibut
esComp_
ID and No ar
enot
det
erminedbyt
hepri
mar
ykey.Hencetherel
ati
oni
snotin1NF.
4.3.2.2SecondNor malForm(2NF)
Ar elat
ionisi
nsecondnor malfor
mifiti
sin1NFandal lnon-pr
imar
ykeyattr
ibut
esmustbe
ful
lyfuncti
onal
lydependentuponpri
marykeyattr
ibut
es.IfAandBarefiel
dsinatable,
Bis
ful
lyfuncti
onal
lydependentonAifBisfunct
ional
lydependentonA,butnotanyproper
subsetofA.
I
notherwords,
afunct
ional
dependencyA Bi sful
l
yfunct
ional
dependencyifr
emov
al
ofanyf
iel
dfrom Ar
esult
sinthedependencynotbei
ngsustai
nedanymor e.
Thesecondfr
om (2NF)appl
iest
otableswit
hcomposi
tepr
imarykey(
thepr
imar
ykeyi
s
notasingl
efi
eldr
atheri
tiscomposedoftwoormoref
iel
ds).
Exampl
e:Consi
dert
her
elat
ionSt
udent
:
St
udent
Rol
l
No. Game Name Fee Gr
ade
1 Cr
icket Ali 200 A Rol
l
No Name
2 Badminto Dani
el 150 B
n Gr
ade
3 Cr
icket Beka 200 A
Game Fee
4 Badminto Fati
ma 150 C
n
5 Hockey Kasu 100 A
6 Cr
icket John 200 C
ThePrimar
yKeyi s(Roll
No.,Game)
.EachSt udentcanparti
cipat
einmorethanone
game.Rel
ati
onStudenti
sin1NFbutsti
ll
contai
nsanomal i
es.
Del
eti
onanomaly:Supposeyouwanttodel
etestudentKasu.Hereyoul
osei
nfor
mati
on
72
aboutgameHockeybecausehei
stheonl
ypl
ayerpar
ti
cipat
edi
nhockey
.
I
nser
ti
onanomal
y:Supposeyouwantt
oaddanewgameBasketBal
lhav
ingnost
udent
par
ti
cipat
edi
nit
.Youcannotaddt
hisi
nfor
mat
ionunl
esst
her
eisapl
ayerf
ori
t.
Updat
ionanomal
y:Supposeyouwantt
ochangeFeeofCr
icket
.Her
e,y
ouhav
eto
searchallthestudentspar
ti
cipat
edi
ncr
icketandupdat
efeei
ndi
vi
dual
l
yot
her
wisei
t
producesinconsi
stency.
Thesol ut
ionoft hi
spr obl
em istoseparatePart
ialdependenci
esandf ul
l
yfuncti
onal
dependencies.So,div
ideStudentr
elat
ionintothr
eer el
ati
onsStudent(
Roll
No.,Name),
Games( Game, Fee)andPerfor
mance(Rol
lNo.,Game,Grade)asfol
lows:
St
udent Games Per
for
mance
Rol
lNo. Name Game Fee Rol
lNo Game Gr
ade
1 Ali Cri
cket 200 .
2 Daniel Badmint
o 150 1 Cri
cket A
3 Beka 2 Badmint
o B
n
4 Fati
ma n
Hockey 100 3 Cri
cket A
5 Kasu
6 John 4 Badmint
o C
n
TheRelat
ionsin2NF.Now, Del
eti
on,
Insert
ionand 5 Hockey A
updat
ionoperati
onscanbeperf
ormedwithoutcausi
ng 6 Cri
cket C
i
nconsist
ency.
4.
3.2.
3Thi
rdNor
malFor
m(3NF)
Ar el
ati
oni sinThi
rdNormalFormifi
tisin2NFandnon- pri
marykeyatt
ri
butesmustbe
non-t
ransit
ivel
ydependentuponpri
marykeyat tr
ibut
es.Inotherwor
dsar elat
ioni
sin
3NFifitisin2NFandhav i
ngnotr
ansit
ivedependency.
Thenormal
i
z ati
onof2NFtabl
esto3NFi nvolvesther
emovaloft
ransi
ti
vedependenci
es.
Weremovet hetr
ansi
ti
vel
ydependentfi
elds(s)fr
om t
hetabl
ebyplaci
ngthefiel
d(s)i
na
newtabl
ealongwithacopyofthedeter
mi nant(
s).
Consi
dertherel
ati
onSt
udent
Student
Rol
lNo Name Semest Host
e Name
. er l
1 Lel
lo 1 H1 Rol
l
No Semest
er
2 Ebisa 2 H2
Host
el
3 Hana 1 H1
4 Newa 4 H4 (
b)
y
73
5 Kedi
r 3 H3
(a)
ThePri
mar yKeyi s(RollNo.
).Thecondi
ti
oni sdif
fer
entHost eli
sall
ott
edfordif
fer
ent
semest
er.Studentrelat
ionisi
n2NFbutstil
lcontai
nsanomal i
es.
Del
eti
onanomal y:Ifyouwantt odeletestudentEbisa.Youl osei
nformat
ionabout
Host
elH2becausehei stheonlyst
udentst
ayinginhostelH2.
I
nser
ti
onanomal
y:I
fyouwantt
oaddanew Host
elH8andt
hisi
snotal
l
ott
edt
oany
st
udent
.youcannotaddt
hisi
nfor
mat
ion.
Updat
ionanomal
y:I
fyouwantt
ochangehost
elofal
lst
udent
soff
ir
stsemest
er.You
hav
et osearchal
lthestudent
soff
ir
stsemest
erandupdat
ethem i
ndi
vi
dual
l
yot
her
wise
i
tcausesinconsi
stency
.
Thesolut
ionofthi
sproblem i
stodiv
ider
elati
onStudenti
ntotworel
ati
onsSt
udent
(
Rol
lNo.Name,Semest
er)andHost
els(
Semester,
Hostel
)asf
oll
ows:
St
udent
Rol
lNo. Name Semest Semest
er Host
el
er 1 H1
1 Lel
lo 1 2 H2
2 Ebi
sa 2 Host
els
3 H3
3 Hana 1 4 H4
4 Neway 4
5 Kedi
r 3
Relati
onsin3NF.Now, delet
ion,
inser
ti
onandupdati
onoperati
onscanbeper f
ormed
wi
thoutcausi
nginconsist
ency.
Exampl e.Gi
vent herel
ati
onBANK( Account
#,Cust
_No,Cust_Name,Balance).Determi
ne
whetherther
elat
ionisin1NF,2NF,3NForunnormali
zd.I
fiti
snotin3NF,converti
tinto3NF
r
elati
ons.
Sol
uti
on:Si
ncet
her
edoesnotexi
stmul
ti
-v
alueat
tr
ibut
es,
hencet
her
elat
ioni
satl
east
1NF.
- Theredoesnotexi
stanypar
ti
aldependencyast
hepr
imar
ykeyhasonl
yone
at
tr
ibut
e.
- Ther
eexi
stsat
ransi
ti
vedependencyi
.e.Cust
_No→ Cust
_Name
Hencet herel
ati
onisnoti
n3NF.Toconvertt
hisrel
ati
onint
o3NF,makeanew r el
ati
on
CUSTOMERSwi t
hatt
ri
but
esCust
_NameandCust _
Noonwhi chi
tdepends.Ther
efore,t
he
rel
ations i
n 3NF ar
e CUSTOMERS(
Cust
_ No,Cust_Name)BANK( Account
#,Cust _
No,
Balance).
74
Example.Giv
en t
he dependency di
agr
am bel
ow.The pr
imar
y key at
tr
ibut
es ar
e
under
li
ned.
C1 C2 C3 C4 C5
a)I
( dent
if
yanddi
scusseachoft
hei
ndi
cat
eddependenci
es.
b)Cr
( eat
eadat
abasewhoset
abl
esar
eatl
easti
n3NF,showi
ngdependencydi
agr
am f
or
eacht
abl
e.
Sol
.
(
a)Ther
eexi
stsapar
ti
aldependencyC1→ C2,
sinceC2dependsonl
yonC1r
athert
han
ont
heent
ir
epr
imar
ykey(
C1,
C3)
.
- Ther
eexist
satransit
ivedependencyC4→ C5,
sinceC5dependsont
heat
tr
ibut
e
C4,
whichisnotapartofthepri
marykey.
Thereexi
stsaf
unct
ionaldependencyC1,
C3→ C2,
C4,
C5,
sinceC2,
C4,
andC5depend
onthepri
marykey(
C1,C3).
(
b)Thegi
venr
elat
ioni
sdecomposedi
nto3NFandt
heobt
ainedr
elat
ionsar
e
(
i) R1(
C1,
C2)wi
thFD{
C1→ C2}
.TheFDdi
agr
am i
s
C1 C2
(
i)R2(
i C1,C3,C4)wi
th FD{
C1,
C3→ C4}
.TheFDdi
agr
am i
s
(
ii
i) R3 (
C4,C5)wi
th FD{
C4→ C5}
.TheFDdi
agr
am i
s
4.3.2.4Boy ceCoddNormal C4 C5 For
m( BCNF)
BCNFi sast r
ictfor
matof 3NF.Arel
ati
oni sinBCNFifandonl
yifal
l
determinantsarecandi
dat
ekey
s.BCNFdeal
swi
thmult
ipl
ecandidatekeys.Rel
ati
onsi
n3NF
al
socont ainsanomali
es.
TheBoy
ce-
CoddNor
malFor
misanext
ensi
ont
othe3NFf
ort
hespeci
alcasewher
e:
- Ther
ear eastt
eatl wocandi
dat
ekeysi
nthet
abl
e,
- Al
lthecandi
dat sar
ekey ecomposi
tekeys,
and
- Ther
eis ov
erl
appi
ngf
iel
d(s)i
nthecandi
dat
ekey
s(t
her
eisatl
eastonef
iel
din
common).
Whenat abl
esati
sfi
esalltheseconditi
ons,the3NFcan’teli
minat
eallf
ormsoftransi
ti
ve
dependency.Foratabl
et obei ntheBCNF,i tmustbei nthe3NF,andallf
iel
dsinalli
ts
candidat
ekeysmustbefunct i
onal
l
yi ndependent
.Vi
olat
ionoftheBCNFisqui
terar
e,itmay
onlyhappenundert
heaboveconditions.
75
Consi
dert
her
elat
ionSt
udent
(
a)
St
udent Ov
erl
oade
Cdandi
dat
K
eey
Rol
lNo Subjec Teache
. t r
1 C T1 Rol
l
No Rol
l
No
2 C++ T2
3 C T1 Teacher Subj
ect
4 Java T3 Subj
ect Teacher
5 Java T3
1 Oracl
e T5
6 Oracl
e T5
3 C++ T2
7 VB T4
8 Oracl
e T6
Assumpti
ons:St
udentcanhavemorethan1subj
ect
.ATeachercant
eachonl
y1
subj
ect
.Asubjectcanbetaughtbymorethan1t
eacher
.
Her
e,t
her
ear
etwocandi
dat
ekey
s(Rol
l
No.
,Subj
ect
)and(
Rol
l
No.
,Teacher
)
Rel
ati
onSt
udenti
sin3NFbutst
il
lcont
ainanomal
i
es.
I
nr elat
ionStudent
,candidat
ekeyi sover
loaded.Youcanfi
ndTeacherbyRoll
No.and
Subject
.Youcanal sofindSubj
ectbyRoll
No.andTeacher.Her
eRollNo.i
soverl
oaded.
Youcanal sofi
ndsubjectbyTeacher.
Rol
l
No.
,Subj
ect Teacher
Det
ermi
nant
s Teacher Subj
ect
Rol
l
No.
,Teacher Subj
ect
Det
ermi
nant
si
nrel
ati
onst
udent
.
Thesolut
ionoft
hispr
obl
em i
stodi
vi
der
elat
ionSt
udenti
ntwor
elat
ionsSt
u-Teacand
Teac-
Sub:
St
u-Teac Teac-
Sub
Rol
lNo. Teacher Teacher Subject
1 T1 T1 C
2 T2 T2 C++
3 T1 T3 Java
4 T3 T4 VB
5 T3 T5 Oracle
1 T5 T6 Oracle
76
6 T5
3 T2
7 T4
8 T6
Teac-
Sub
Candi
dat
eKey(Teacher
)
Stu-Teac(Rol
lNo.,
Teacher)
Candidat
eKey( Rol
lNo.
,Teacher).Inthi
ssoluti
onal
ldet
erminantsarecandi
dat
ekey
s.
Example:Descri
bethefol
lowingEmployee_
Ov er
ti
metabl
ethatviol
atestheBCNF.
Assumethattheemployeenamei suni
que.
Empl
oyee_
Over
ti
me
EmpI
d Empname Overt
imemont
h OTHour
s
A8 AbebeKebede Januar
y 5
A8 AbebeKebede Apri
l 10
A5 AhmedMohammed Januar
y 2
B6 Zahar
aHagos Apri
l 3
A5 AhmedMohammed March 2
Thecandi datekeysar e,(EmpI
d,Overt
ime_month)and( Empname,Ov er
time_ month)
and the overlappi
ng fi
eldisthe Over
ti
me_mont h.Normali
zing t
histablet o BCNF
requir
esthistabletobedecomposedintotwotableshav
ingthefol
lowingfi
elds.Tabl
e1
having t
heEmpI d and Empname,and Table2 havi
ng EmpId,Ov er
ti
me_mont h,and
Othoursfi
elds.
4.
4.Denor
mal
izat
ion
Denor
mali
zat
ionist
heprocessofatt
empti
ngtoopt
imi
zet
her
eadper
for
manceofa
dat
abasebyaddi
ngr
edundantdat
aorbygr
oupi
ngdat
a.
Defini
ti
on:Denor mal i
zationcanbedescr i
bedasapr ocessf orreducingt hedegreeof
normalizati
on wi th the ai m of i mpr ovi
ng quer y pr ocessi ng performance. Or
Denormal i
zati
oni sthepr ocessofput ti
ngonef actinnumer ouspl aces.Oneofthemai n
purposesofdenor malizati
oni st oreducethenumberofphy sicaltablesthatmustbe
accessedt oretr
ievethedesi reddat abyreducingt henumberofj oinsneededtoder i
vea
query answer .This speeds dat aretri
evalatt he expense ofdat a modificat
ion.
Denormal i
zati
onhasbeenut i
lizedinmanyst rategicdatabasei mpl ementati
onstoboost
databaseper f
ormanceandr educequer yresponset i
mes.Oneoft hemostusefulareas
forapplyingdenor malizati
ont echni
quesi sindat awar ehousi ngi mplementat
ionsf or
datami ni
ngt r
ansactions.
77
Theprimar ygoal
sofdenor malizat
ionaretoimprovequeryperf
ormanceandtopr
esent
theend-userwithal esscompl exandmor euser-or
ient
edv i
ew ofdata.Thi
sisi
npart
accomplishedbyr educi
ngt henumberofphy si
caltabl
esandr educi
ngthenumberof
actual
joinsnecessarytoderiv
et heanswertoaquery
Adv
ant
agesofDenor
malizat
ion
- Itcani
mproveper
formancebymi
nimi
zi
ngt
heneedf
orj
oins.
- I
tcani
mpr
oveper
for
mancebyr
educi
ngt
henumberoff
orei
gnkey
sont
abl
es.
- I
tcani
mpr
oveper
for
mancebyr
educi
ngt
henumberofi
ndexes,
sav
ingst
orage
spaceand
r
educi
ngdat
amodi
fi
cat
iont
ime.
- I
tcani
mpr
oveper
for
mancebypr
ecomput
ingaggr
egat
eval
ues,
thati
s,comput
ing
t
hem at
dat
amodi
fi
cat
iont
imer
athert
hanatsel
ectt
ime
- I
nsomecasesi
tcani
mpr
oveper
for
mancebyr
educi
ngt
henumberoft
abl
es.
Di
sadv
antagesofDenormal
izati
on
- I
tusual
lyspeedsr
etr
ievalbutcansl
owdat
amodi
fi
cat
ion.
- I
tisal
way
sappl
i
cat
ion-
speci
fi
candneedst
ober
e-ev
aluat
edi
ftheappl
i
cat
ion
changes.
- I
tcani
ncr
easet
hesi
zeoft
abl
es.
- I
nsomei
nst
ances,
itsi
mpl
i
fiescodi
ngbuti
nsomeot
her
s,i
tmakescodi
ngmor
e
compl
ex
78
REVI
EW QUESTI
ONS
Chooset
hebestanswerf
rom agi
venal
ter
nat
ives
1.Thef unct i
onal dependencyA- >Bf orr elati
onschemaR( A, B,C,D)i
mpli
esthat
A.not wot uplesi nRcanhav ethesamev aluef orat tri
but eB
B. not wot uplesinRcanhav et hesamev aluef orat tr
ibuteA
C.anyt wot uplesi nRt hathav et hesamev aluef orAmusthav ethesamev al
ue
forB
D.anyt wot uplesi nRt hathav et hesamev aluef orBmusthav ethesamev al
ue
forA
2.Whichoneoft hef ollowingstatement sifFALSE?
A.Anyr elat i
onwi tht woat tr
ibutesi sinBCNF.
B.Ar elati
oni nwhi chev erykeyhasonl yoneat tributeisi n2NF.
C. Apr imeat tr
ibutecanbet ransiti
v elydependentonakeyi na3NFr el
ati
on.
D.Apr imeat tri
butecanbet r
ansi ti
velydependentonakeyi naBCNFr el
ati
on
3.Thi
rdnor mal formi sbasedont heconceptof
A.Cl osur eDependency C.Tr ansitiveDependency
B. Nor mal Dependency D.Funct i
onal Dependency
4.Decomposi ti
onhel pi neliminatingsomeoft hepr oblemsofbaddesi gn
A.Redundancy C.i nconsi stencies
B. Anomal ies D.al loft heabov e
5.Referent i
al i
ntegr it
yi sdirectl
yrelatedt o
A.Rel ationkey C.For eignkey
B. Pr imar ykey D.Candi dat ekey
6.Whichnor mal formi sconsi deredasadequat ef orusual databasedesi
gn?
A.2NF C.3NF
B. 1NF D.BCNF
7.Whichoft hef oll
owingi st r
ue?
A.Ar elationi n3NFi salway sinBCNF
B.Ar elationi nBCNFi sal waysi n3NF
C.BCNFand3NFar etotall
ydifferent
D.Ar elationi nBCNFi si n2NFbutnoti n3NF
79
8.Ifarel
at i
oni si n2NFand3NFf ormst hen
A.Nonon- pr imar ykeyat tr
ibut eisfunctionallydependentonot hernon-primarykey
att
ributes.
B. Nonon- pr i
mar ykeyat tribut eisf unctionall
ydependentonpr i
mar ykey
att
ributes.
C.Al lattr
ibut ear efunct i
onal lyindependent .
D.Pr imar ykeyat tr
ibutei sf unct i
onallyindependentofal lnon-pri
meat tri
butes.
9.Multi
valueddependencyamongat tri
butei scheckedatwhi chnor mal f
orm?
A.2NF C.3NF
B. BCNF D.1NF
10.
Ifarel
at i
oni si n2NFt hen
A.Ever ycandi dat ekeyi sapr imar ykey
B.Ever ynon- pr i
mar ykeyat tri
but eisfullyfunct i
onall
ydependentoneach
relati
onkey
C.Ever yat tribut eisf unct ional lyindependent
D.Ever yr elational keyi sapr i
mar ykey
11.
Whichoft hef oll
owi ngy ieldsbet terper f
or mance?
A.Denor mal i
zat ion C.Nor mali
zati
on
B.Dependency D.Compr ession
12.
Whatisoneoft hef ollowi ngdescr i
besanupdat eanomaly ?
A.Onet ransact ionr eadsanel ementt hatwasupdat edbyanear l
ier
,uncommi t
ted
tr
ansact i
on.
B.Theappl icat i
onwant st oupdat eaf oreignkeyt oanewv aluethatdoesnotexi st
s
i
nt her efer encedr elat i
on.
C.Thesamei nf ormat ioni sst oredr edundant lyinthedat abase,andonl ysome, but
notall copi esar eupdat ed.
D.Noneoft heabov e
13.
Whichoft hef oll
owi ngst atement sbestdescr i
best hemai nr easonforrepresentinga
rel
ati
onal dat abasei n1NF?
A.Toachi evephy sicaldat ai ndependence.
B.Tor emov edat aanomal ies( i
nserti
on, updat e,del
eti
onanomal i
es).
C.Tosav espaceondi sk.
D.Al loftheabov e
14.
Whichoft hef oll
owi ngst atement sbestdescr i
best hemai nr easonforrepresentinga
rel
ati
onal dat abasei nBCNF?
A.Toachi evephy sicaldat ai ndependence.
B.Tor emov edat aanomal ies( i
nserti
on, updat e,del
eti
onanomal i
es).
C. Tosav espaceondi sk.
D.Noneoft heabov e
15.
Whichoneoft hef ol
lowi ngi scor r
ect?
A.Al lfunct i
onal dependenci esar emanyt omanyr elat
ionship.
80
B. All
functi
onal dependenci
esar emanyt oonerelat
ionshi
p.
C.Allfunct
ionaldependenciesareonet oonerelat
ionship.
D.Noneoft heabov e
16.
Thekeysthatcanhav eNULLv al
uesar e
A.Primarykey C.Uniquekey
B.Foreignkey D.BothAandC
17.
BCNFcanbev i
olatedonlyifthetablecontainsmoret hanone__
__key
.
A.Pri
mar y C.candidate
B.for
eign D.secondary
CHAPTERFI VE
RECORDSTORAGEANDPRI MARYFI LEORGANI ZATION
5.1.I ntroduct ion
Dat abasesar est ored phy sicall
yasf il
esofr ecords,whi char et ypicall
yst ored on
magnet icdi sks.Thi schapt erdealwi tht heor gani zationofdat abasesinst orageandt he
techni quesf oraccessi ngt hem ef f
icient l
yusi ngv ariousal gorit
hms,someofwhi ch
requi re auxi liary dat a struct ur
es cal led indexes.Thi s chapteral so introduce t he
concept sofcomput erstoragehi erarchiesandhowt heyar eusedi ndat abasesy stems,
adescr ipti
onofmagnet icdiskst oragedev i
cesandt heircharacteri
stics,andweal so
brieflydescr ibemagnet ict apest oragedev i
ces,descr i
beamor erecentdat ast orage
syst em al ter nat i
vecal l
ed RAI D(RedundantAr ray sofI nexpensive( orI ndependent )
Disks)whi chpr ov idesbet terreli
abili
tyandi mpr ov edper formance.
Recor dst or agebasi cs:
The col l
ect ion ofdat at hatmakes up a comput erized database mustbe st ored
phy sical l
yonsomecomput erst oragemedi um.TheDBMSsof t
warecant henr etrieve,
updat e,andpr ocesst hisdat aasneeded.Comput erst oragemedi af orm ast orage
hierar chyt hati ncludest womai ncategor i
es:
- Pr i
mar yst orage:Thi scategor yi ncl
udesst or
agemedi athatcanbeoper atedon
direct lybyt hecomput ercentralpr ocessi nguni t( CPU),suchast hecomput er
mai nmemor yandsmal l
erbutf astercachememor i
es.Primar ystorageusual l
y
prov idesf astaccesst odat abuti soflimi t
edst oragecapaci ty
.
- Secondar yst orage:Thi scategor yincl udesmagnet icdisks,opt i
caldi sks,and
tapes.Thesedev i
cesusual l
yhav eal ar gercapaci ty,costless,andpr ovidesl ower
accesst odat at handopr imar yst or agedev ices.Dat ai nsecondar yst orage
81
cannotbepr
ocesseddi
rect
lybyt
heCPU;i
tmustf
ir
stbecopi
edi
ntopr
imar
y
stor
age.
StorageofDat abases:Dat abasest y pical lyst or el argeamount sofdat at hatmust
persistov erl ongper iodsoft i
me.Thedat ai saccessedandpr ocessedr epeat edl y
duringt hisper iod.Thi scont rast swi tht henot i
onoft ransientdat ast ructurest hat
persistf oronl yal i
mi tedt imedur ingpr ogr am execut ion.Mostdat abasesar est ored
permanent ly( orper sistent ly )onmagnet icdi sksecondar yst orage,f ort hef ol l
owi ng
reasons:
- Gener al l
y ,databasesar et ool ar get of itent i
relyi nmai nmemor y.
- The ci rcumst ances t hatcause per manentl oss ofst ored dat a ar ise l ess
frequent lyf ordi sk secondar yst orage t han f orpr i
mar yst or age.And ot her
secondar yst or agedev ices—asnonv olatilest or age,wher easmai nmemor yi s
of t
encal ledv ol atilest or age.
- Thecostofst or ageperuni tofdat ai sanor derofmagni tudel essf ordiskt hanf or
pr i
mar yst orage.
Someoft henewert echnol ogi es—suchasopt icaldi sks, DVDs, andt apej ukeboxes—ar e
l
ikelyt opr ov i
dev iableal ternat ivest ot heuseofmagnet icdi sks.
Magnet ict apesar ef requent lyusedasast or agemedi um f orbacki ngupt hedat abase
becausest orageont apecost sev enl esst hanst or ageondi sk.Howev er ,accesst odat a
ont apei squi tesl ow.Dat ast oredont apesi sof f-
line;t hati s,somei nt erventionbyan
oper ator —oranaut omat icl oadi ngdev ice—t ol oadat apei sneededbef or ethi sdat a
becomesav ailabl e.Incont rast ,di sksar eon- l
inedev icest hatcanbeaccesseddi r
ect ly
atanyt i
me.
Thet echni quesusedt ost or el argeamount sofst ruct ur eddat aondi skar ei mpor tant
fordat abasedesi gner s,theDBA, andi mpl ement er sofaDBMS.Dat abasedesi gner sand
theDBAmustknowt headv ant agesanddi sadv ant agesofeachst or aget echni quewhen
theydesi gn, i
mpl ement ,andoper at eadat abaseonaspeci ficDBMS.
Ther ear esev er alprimar yf ileor gani zat ions,whi chdet er mi nehowt her ecor dsofaf i
l
e
arephy sicallypl acedont hedi sk,andhencehowt her ecor dscanbeaccessed.Aheap
fi
le( orunor der edf i
le)pl acest her ecor dsondi ski nnopar ti
cularor derbyappendi ng
new r ecor dsatt heendoft hef i
le,wher easasor tedf il
e( orsequent i
alf i
le)keepst he
recor dsor der edbyt hev alueofapar ticul arf ield( cal ledt hesor tkey ).Ahashedf ileuses
ahashf unct i
onappl iedt oapar ti
cul arf iel d( calledt hehashkey )todet er mi near ecor d’
s
placementondi sk.Ot herpr i
mar yf i
l
eor gani zat ions, suchasB- tr
ees, uset reest ructur es.
RedundantAr rayofI ndependentDi sks( RAI D)i sat echnol ogyt oconnectmul tipl
e
secondar yst or agedev icesanduset hem asasi ngl est oragemedi a.RAI Dconsi stsof
anar rayofdi sksi nwhi chmul ti
pl edi sksar econnect edt ogethert oachi evedi fferent
goals.RAI Dl ev elsdef inet heuseofdi skar ray s
5.
2.Fil
eorgani
zat
ionconcept
s
Afil
eorgani
zat
ionisawayofarr
angi
ngt
her
ecor
dsi
naf
il
ewhent
hef
il
eisst
oredon
82
secondarystorage(disk,tapeet c.
).Thedi ffer
entwaysofar r
angi
ngt herecordsenabl
e
dif
ferentoperati
onst obecar ri
edoutef f
icientl
yoverthefi
le.Adatabasemanagement
system support
ssev eralfi
l
eor gani
zationtechniques.ThemostimportanttaskofDBAis
tochooseabestor gani zat
ionforeachf i
le,basedoni t
suse.Theorganizat
ionofrecor
ds
i
naf i
leisinf
luencedbynumberoff actorst hatmustbetakenintoconsiderati
onwhil
e
choosingapar t
icul
artechnique.Thesef actorsare
-f astretrieval,updati
onandtransferofrecords,
- ef f
icientuseofdi skspaceandmani pulat
ion
- hight hroughput ,
-t ypeofuse,
- secur i
tyf r
om unaut hori
zedaccess,
- scal abil
ity,andreductioni
ncost
- Pr otectionf r
om failur
e.
Afil
eisacoll
ecti
onofrel
atedsequenceofrecor
ds.Acoll
ecti
onoffiel
dnamesandt heir
corr
espondi
ngdatatypesconsti
tutesarecor
d.Adatatype,associ
atedwit
heachfield,
speci
fi
esthetypesofval
uesafieldcant
ake.Allr
ecor
dsinaf i
leareofthesamerecord
ty
pe.
5.2.1Recor dsandRecor dTy pes
Datai sgener all
yst oredint hefor
m ofr ecor
ds.Ar ecordisacoll
ecti
onoff i
eldsordat a
i
temsanddat aitemsi sf or
medofoneormor eby t
es.Eachr ecor
dhasauni que
i
dent if
iercal l
edrecor d-
id.Therecordsinaf i
leareoneoft hefoll
owingtwot ypes:
a) Fixedlengthr ecords.
b) Va r
iablelengthrecords.
5.2. 1.
1Fi xedLengt hRecor ds
Ev eryr ecor dint hef i
lehasexact lythesamesi ze( i
nby t
es).Ther ecordsl ot
sar e
uniform andar ear r
angedi nacontinuousmanneri nthefil
e.Arecordisidenti
fiedusing
bothr ecor d-i
dandsl otnumberoft her ecor
d.Thef oll
owingshowsast ructureoffixed
l
engt hSTUDENTr ecordandapor ti
onofaf i
l
eoff ixedlengthr
ecords.
TypeSTUDENT=r ecord
NAME=char (20);
Roll
No=char (5);
DOB=char (8);
end
Name Rol
lNo. DOB
Chal
a 3234 28-
02-
75
Abebe 5132 20-
05-
80
John 3535 24-
10-
77
Advant
ageofFi
xedLengt
hRecor
ds
83
- Inser
ti
onanddel
eti
onofr
ecor
dsint
hefil
ear
esimpl
etoimplementsi
ncet
he
spacemadeavai
labl
ebyadel
etedr
ecor
dissameasneededtoinser
tanew
recor
d.
Di
sadvant
ageofFi
xedLengt
hRecor
ds
- Infi
xedl engt
hr ecords,si
ncet helengt
hofr ecordisf i
xed,i
tcauseswast ageof
memor yspace.Forexampl e,i
fthelengthissetupt o50char acter
sandmostof
therecordsar elessthan25char acter
s,itcauseswast ageofpr eci
ousmemor y
space.
- Iti
sani nfl
exibl
eappr oach.Forexample,ifi
tisrequiredtoincreasethel
engthof
arecord,thenmaj orchangesinprogram anddat abaseareneeded.
5.2.1.2.VariableLengthRecords
Ev er
yr ecordinthefil
eneednotbeoft hesamesi ze(i
nby tes)
.Ther ef or
e,ther ecor
dsin
thefil
ehav edi f
fer
entsizes.Themaj orproblem wit
hvariablel
engt hr ecordi st hatwhen
anewr ecordistobei nser
ted,anempt yslotoftheexactlengt
hisr equired.Ift hesloti
s
smaller,itcannotbeusedandi fiti
st oobig,theextr
aspacei sj ustwast ed.Ther eare
twomet hodst ostorevari
ablelengthrecordswithafixedlengthr epresent ation.These
arer eserved spaceand poi nters.A fil
emayhav ev ar
iabl
el engt hr ecor dsduet o
fol
lowingr easons:
-Oneormor
ethanonef
iel
dsofar
ecor
dar
eofv
ary
ingsi
zebutt
her
ecor
dsi
nthe
f
il
ear
eofsamer
ecor
dty
pe.
-Oneormor
ethanonef
iel
dsmayhav
emul
ti
plev
aluesf
ori
ndi
vi
dualr
ecor
dsand
ar
ecal
l
edr
epeat
ingf
iel
dsbutt
her
ecor
dsi
nthef
il
ear
eofsamer
ecor
dty
pe.
-Oneormor
ethanonef
iel
dsar
eopt
ionali
.e.
,theymayhav
eval
uesf
orsomebut
notf
oral
lrecor
ds.Thef
il
erecor
dsi
nthi
scasear
eal
sooft
hesamer
ecor
dty
pe.
-Thef
il
econt
ainsr
ecor
dsofdi
ff
erentr
ecor
dty
pesanddi
ff
erentsi
zes.
Advant
ageofVar
iabl
eLengt
hRecor
ds
- I
treducesmanualmistakesasdatabaseautomatical
l
yadjustthesizeofr
ecor
d.
- I
tsaveslotofmemoryspaceincaseofr ecordsofvari
ablelengt
hs.
- I
tisaflexi
bleappr
oachsincefut
ureenhancementsarev eryeasytoimpl
ement.
Di
sadvant
ageofVar
iabl
eLengt
hRecor
ds
- Itincr
easestheover
headofDBMSbecausedat
abasehav
etokeepr
ecor
doft
he
sizesofall
recor
ds.
5.
2.2TypesofFiles
Thefol
lowingthr
eetypesoff
il
esareusedindatabasesyst
ems:
1.Masterfi
le
2.Transact
ionfi
le
3.Reportfi
l
e.
1.Masterfil
e:Thisfil
econt
ainsinf
ormati
onofper manentnat ureabouttheenti
ti
es.
Themast erfi
leactasasourceofref
erencedataforprocessingtr
ansacti
ons.They
84
accumulatetheinformati
onbasedont het ransacti
ondata.
2.Transact
ionf i
le:Thisfi
lecontainsrecordst hatdescr
ibet heact
ivi
ti
escar r
iedoutby
theorganizati
on.Thi sfil
eiscr eat
edasar esul
tofpr ocessi
ngt r
ansactionsand
prepar
ingt r
ansactiondocument s.Thesear ealsousedt oupdatethemast erf
il
e
permanently.
3.Reportfil
e:Thi sf i
leiscreat
edbyext ractingdataf r
om t hediff
erentrecordsto
prepar
ear eporte.g.Areportf
ileabouttheweekl ysal
esofapar ti
cul
aritem.
5.3Fil
eor ganizationt echni ques
Af i
l
eor ganizationi sawayofar rangingt herecor
dsi nafi
l
ewhent hefi
leisstoredon
secondaryst orage( disk,t apeet c).Ther earediff
erentt
ypesoffi
leorgani
zati
onst hat
areusedbyappl i
cations.Theoper ationst obeperfor
medandtheselecti
onofst or
age
devi
cear et hemaj orfact orst hatinfluencethechoiceofapart
icul
arfil
eorganizat
ion.
Thediffer
entt ypesoff i
leor ganizationsar e:
1.Heapf i
leor ganizat i
on
2.Sequent ialfil
eor ganization
3.I
ndexed—Sequent ial f
il
e
organizat i
on
4.Hashi ngorDi r
ectf il
eor ganization.
5.3.1HeapFi leOr ganization( Fil
esofunor deredr ecor
ds)
Inthisf il
eorganizati
on,t her ecordsarest oredi nt hefi
le,intheor derinwhi chtheyar e
i
nser ted.Allthenew r ecor dsar estoredatt heendoft hef il
e.Thisf i
leorganizat
ioni s
alsocal ledPILEFILE.Thi sor ganizati
oni sgener al l
yusedwi thaddi t
ionalaccesspat hs,
l
ikesecondar yindexes.I nser ti
nganewr ecor disv eryfastandef fi
cient.Butsearchinga
recordusi nganysear chcondi ti
oni nvolvesal i
nearsear cht hrought hef i
le,whichi s
compar ati
vel
ymor eti
meconsumi ng.Delet i
ngar ecor
df rom aheapf i
leisnotef fi
cient
asdel etionofrecordsr esultedinwast ageofst oragespace.I tisgenerallyusedtost ore
smal lfil
esori ncaseswher edat aisdi ff
iculttoor ganize.Itisalsousedwhendat ai s
coll
ect edatonepl acepr i
ort opr ocessing.
Advant
agesofHeapFi
l
eOr
gani
zat
ion
- I
nsert
ionofnewr ecor
disfastandeffici
ent
.
- Thefi
ll
ingfact
orofthi
sfil
eorganizat
ionis100%.
- Spaceisful
lyut
il
izedandconserv
ed.
Di
sadvant
ageofHeapFi
leOr
gani
zat
ion
- Searchingandaccessi
ngofr ecordsisverysl
ow.
- Deleti
onofmanyr ecordsresul
tinwastageofspace.
- Updationcostofdataiscompar ati
vel
yhigh.
- I
thasl imit
edappl
icati
ons.
5.3.2Sequenti
alFi
leOrganizat
ion(Fi
lesofor der
edrecor
dsorsor t
edr ecor
ds)
I
nsequent i
alfi
leorgani
zati
on,recor
dsar estoredinasequenti
alorderaccordingt
othe
“searchkey”.A Searchkeyi sanat tr
ibut
eorasetofat t
ri
buteswhi char eusedto
85
seri
alizet herecords.I
tisnotnecessar ythatsearchkeymustbepr i
mar ykey.
Itist hesi mplestmethodoff il
eor ganizati
on.Sequentialmethodi sbasedont ape
model .Dev i
ceswhosuppor tsequent ialaccessar emagnet i
ct apes,cassett
es,car d
readerset c.Editor
sandcompi lersalsouset hisapproachtoaccessf i
les.
St r
uct ureofasequent ialfi
leisshowni nt hefoll
owingfigur
e.Ther ecordsarestor edin
sequent ialorderoneaf teranother.Tor eachatt heconsecutiv
er ecordf r
om anyr ecord
pointersar eused.
ThePoi nter
sar eusedforfastretr
ievalofrecords.Beginni
ngoffil
e
Recor
d1
Recor
d2
Recor
d3
Recor
dN-
2
Recor
dN-
1
Recor
dN Endoff
il
e
Fi
g.Sequenti
alfi
leorgani
zati
on.
Tor eadanyrecordfrom t
hefil
estartsear
chingfrom thever
yfi
rstrecor
dwit
hthehelpof
searchkey.Sequenti
alfi
leorgani
zati
ongivesrecordsinsort
edform.Thisor
gani
zat
ionis
usedinsmal l
sizefi
les.
5.3.2..
1.Fil
eOper ati
onsonSequent i
all
yOrgani
zedFiles
Variousoperat
ionst hatcanbeper for
medonsequent ialf
il
esar easfol
lows:
a)Cr eati
ngasequent i
alf i
le:Tocreateanew f il
e,fir
stfreespacei ssearchedin
memor y.Af
tersear ching,enoughspaceforfi
le,al
locatethatspacet othenewf i
l
e.
Nameandphy sicall
ocat i
onofnewf i
lei
senteredinfi
lesystem di
rectory
.
Sear
ch f
reespace
I
ffound
Al
l
ocatespacef
or
newf i
le
Enternameandphysi
cal
l
ocati
onofnewfi
l
ein
fi
lesyst
emdir
ect
ory
Fig.Stepsofcr eati
ngasequent i
alfi
le.
b)Openanexi stingf i
le:Toopenanyf i
le,enterthenameoff il
e.Thisnamei ssearched
i
nf i
lesy stem di r
ectory.Af t
ermat chingt hename,r ecordsi nthefilearetransfer
red
from secondar ymemor ytopr i
mar ymemor y.Now, t
hef i
l
ei sreadytor ead/wri
te.
c)Closingaf i
le:Whent askov erf i
l
ei scompl etedthencloset hatf i
le.Thememor y
spaceal locatedf ort hatf i
leinpr i
mar ymemor yi
sdeal l
ocated.Iff i
lewasopened
automat i
callywi t
hanypr ogrammet heni twillbeclosedaut omaticall
yafterending
thatprogramme.
d)Readingasequent ialfi
le:Tor eadanyr ecordf rom asequent i
alfi
l
ei tisnecessaryto
startfr
om begi nningoff i
leunt i
lrecordi sfindorEOFi soccur r
ed.Youcannotgo
86
di
rect
lyt
oanypar
ti
cul
arr
ecor
d.Onl
yli
nearsear
chcanbeusedt
osear
chanyr
ecor
d.
Begi
nning Curr
ent Endi
ng
of
fil
e posi
ti
on offi
le(
EOF)
Readi
ng
Not
e:Insequenti
alf
il
esystem, updat
e,delet
e,i
nser
tandappendcannotbeperfor
med
onanyrecorddi
rect
ly.Thereisaprocedur
etoperf
orm al
ltheseoper
ati
ons.
Procedur etoUpdat eFi le:
Step1.Or i
ginalf i
leisknownasOl dMast erf i
le.Makeanewf i
lewhichisknownasNew
Mast erf il
easshowni nt heabov eFi gure.
t
h
Step2.Toupdat en r ecor d, fi
rstcopyal l thepr evousn–1r
i ecordstonewmast erfi
le.
th
Step3.Makenecessar yupdat i
onst on r ecor d.
Step4.Nowcopyal lremai ningr ecor dsi ncl udingupdat ednthrecordtoNewmast erf i
l
e
andol dmast erf il
ei sdel eted.
Themaj orpr obl em i st hati tisv er ycost l
yt omakeNew Mast erfi
leforev er
ysi ngl
e
updat i
on.Sot hemodi fi
edupdat ionpr ocedur eisasf oll
ows:
Modi f
icat i
oni nPr ocedur e:Useat empor aryf il
eknownast ransacti
onf i
le.The
fol
lowi ngpr ocedur ei sf oll
owedt omakeat ransact i
onf il
eandt henupdat i
ngt herecords.
(
i) Co ll
ectal l t
her equest sf orupdat i
on.
(
i) Co
i pyonl yt hoser ecor dsi nTr ansact i
onf ilefrom oldMast erf i
l
eonwhi ch
updat i
oni st obeper formed.
(
ii
i) Up dat et her ecor ds.
(
iv) No w st artcopy ingr ecor dsf r
om Ol dMast erf i
leandTr ansacti
onf i
letoNew
Mast erf il
eaccor dingl ytot hepr i
mar ykey .
(
v) At lastol dmast erf i
leandt ransact ionf ilearedel et
ed.
e) Addi ngorI nser tionanewr ecord:Toaddori nsertanewr ecordsi nanexi sti
ng
sequent i
al file,thet ransact i
onf i
leisused.
Ex.Consi der , t
heol dmast erf il
eemp- recordsasshownasf oll
ows.
Emp- recor ds( Ol dMast erFi l
e)
Emp- ID Name Sal ar y
1 Ani l 15, 000
7 Suni l 8,000
10 Sahi l 10, 000
Ther ecordst
hatneedtobeaddedarecol
l
ect
edi
nTr
ansact
ionf
il
easshowni
nthe
fol
lowing.
Transacti
onFil
e
Emp- I
D Name Salar
y
5 Sanjay 7,000
12 Ami t 9,000
87
TheEMP- I
Dispr imarykey .Now,addr ecordsinNew Mast erf
il
easshowni nthe
fol
lowi ngFigure.Ifprimarykeyofr ecordinOl dMasterfi
leislessthanrecordin
Transact i
onfil
ethenf i
rstcopyr ecordofOl dMasterFi
l
ei nt
oNewMast erfi
leandv i
ce
versa.Thisprocessisrepeatedunt ilEOFisreachedi
nbothfi
les.
Emp- records(NewMast erFi
le)
Emp- I
D Name Salar
y
1 Anil 15,000
5 Sanjay 7,000
7 Sunil 8,000
10 Sahil 10,000
12 Amit 9,000
TheOl dMasterf il
eandt ransacti
onf i
lear
edeletedaft
eraddi
ngtherecords.
()Del
f eti
onofr ecords:Supposeyouwantt odelet
esomer ecordsfr
om Emp-r
ecor
ds
(asshowni nt hefoll
owi ngFigure)whicharenomor erequi
red.Thenemp-r
ecor
ds
showni nFi gureist akenasol dmasterfil
e.Recordsthatneedtobedelet
edare
storedinTransact i
onf i
le.
TransactionFi
le
Emp- ID Name Salary
1 Ani l 15,
000
12 Ami t 9,
000
Pri
mar y Key ofOl d Mast erfil
ei s matched with pr
imary key ofeach r ecordin
Transacti
onfil
e.Ifpri
mar ykeyisnotmat chedthenrecor
discopiedfrom OldMast erfi
l
e
toNewMast erfi
leotherwisediscardthatrecord.TheprocessisrepeateduntilEOFof
theOldMast erfi
l
ei sreached.Afterthi
sprocess,OldMasterfi
leandtransact
ionf i
lear
e
delet
ed.
Emp- r
ecords(NewMast erFil
e)
Emp- I
D Name Sal ar
y
5 Sanjay 7,
000
7 Sunil 8,
000
10 Sahil 10,000
g)Modi
( f
icati
onofrecords:Supposeyouwantt omodif
yanyr ecor
dofemploy
ee.
ConsiderEmp-recordsinthefollowingFigur
easOl dMasterf
il
e.Recordst
hatneedto
bemodi f
iedarestoredinTransactionfi
l
ewi t
hchangedval
ues.
Tr
ansactionFile
Emp-ID Name Salary
7 Suni
l 12,000
PrimarykeyofOldMasterf i
lei
smat chedwithprimarykeyofeachr ecor
di nTransacti
on
fi
l
e.I fpr
imarykeyismat chedthenmodi f
iedrecordf r
om Transacti
onfi
leiscopiedinto
NewMast erf
il
eother
wiserecordfr
om OldMast erfil
eiscopiedintoNewMast erfi
le.The
processisrepeat
edunti
lEOFi nOldMasterfil
eisr eached.Aft
erthi
sprocess,OldMaster
88
f
il
eandt ransact i
onf i
lear edel eted.
Advantagesofsequent ialfil
es
- Itiseasyt ounder stand.
- E ffici
entf i
l
esy stem f orsmal lsizefi
les.
- Co nstructi
onandr econst ruct
ionoff i
lesar emucheasierincompar
isont
oot
her
fi
l
esy stems.
- Su ppor t
stapemedi a, editorsandcompi l
ers.
- Itcont ai
nssor t
edr ecor ds.
Disadvant agesofsequent ial fi
les
- Inef fi
cientfil
esyst em f ormedi um andl argesizef
il
es.
- Up dationsandmai ntenancear enoteasy .
- Inef fi
cientuseofst oragespacebecauseoff i
xedsizebl
ocks.
- L i
nearsear chtakesmor et ime.
- Be f oreupdationsal ltransact i
onsar est oredsequenti
all
y.
5.3.
3IndexSequent i
al Fi
leOr ganizati
on
I
ndexsequent ialfi
leor ganizati
oni susedt oov ercomet hedi sadvantagesofsequent i
al
fi
le or
gani zation.I tal so pr eserves the adv ant ages of sequent ialaccess.Thi s
organi
zationenabl esf astsear chi
ngofr ecor dswitht heuseofi ndex.Somebasi cterms
associ
atedwi thindexsequent i
alfi
leorgani zat
ionar easf oll
ows:
Bl ock:Bl ockisauni tofstorageinwhi chr ecordsar esav ed.
Index:I ndexi sat ablewi thasear chkeybywhi chblockofar ecordcanbefind.
Poi nter:Poi
nt erisav ari
ablewhi chpoi ntsf r
om indexent r
ytost art
ingaddr
ess
ofbl ock.
Tomani pul ateanyr ecor d,searchkeyofi ndexi sent eredtof indthest ar
ti
ngaddressof
bl
ockandt henr equir
edr ecor dissearchedsequent iall
ywi t
hint heblock.
Fig.I
ndexSequential
File
Component sofanI ndexedSequent ialFi
le
a)Pr imear ea:Duringthecr eati
onofi ndexsequent
ialfil
e,recor
dsarewritteni
npri
me
area.Recor dsaremai ntainedaccor di
ngt oanykey .Hence,primeareamustbea
sequentialfi
le.
b)Ov er
fl
owar ea:Overfl
owar eai susedduringaddi
tionofnewr ecor
ds.Therearetwo
typesofov erfl
owar ea:
- Cy l
inderover f
lowarea:Thi sareaconsist
soff r
eear eaoneachcy l
inderwhi
chis
89
reser vedf orov er
fl
owr ecordsf orthatpar ticul
arcyl
inder.
- I ndependentover fl
ow area:Thi sareai susedt ost oreov erfl
ow recor
dsf r
om
any wher e.
c)Recor dchar act er
isti
cs:Usuall
yf i
xedl engthr ecordsareused.
d)Indexes:I ndexi sacol l
ecti
onofent ri
esandeachent rycor r
espondst oblockof
storage.
- F i
rstleveli ndex:Thelowestl evel i
ndexi sknownasf irstl
evel i
ndex.
- Hi gherl eveli ndex:Higherl evelindexingi susedwhenf i
rstlevelindexbecomes
tool arge.
- Cy l
inderi ndex:Thei ndexescanbemadeaccor di
ngt othehar dwareboundaries.
Cy l
inderi ndexent ri
esconsistsoneent ryf oreachcy l
i
nder.
- Ma sterindex:Thehi ghestlevel ofindexisknownasmast erindex.
Oper
ati
onsonI
ndexSequent
ial
Fil
es
a)Cr eat i
ngai ndexsequent ialf il
e:Af t
eral locatingf reespaceandmakenecessar y
ent ri
esi nf i
lesy st em di rect oryal lrecor dsar ewr ittenintopr i
mear eainsequent ial
manneraccor dingt okeyv alue.
b)Openi ngandcl osi nganexi st i
ngf il
e:Itissameassequent ial
fil
eoper ati
ons.
c)Readi ngr ecor dsf rom ai ndexsequent ialf i
le(orsear chinganyr ecord):Tosear ch
anyr ecor dent ert hekeyv alueofr ecordt henf irstsear chthebl ockofr ecordini ndex
thensear chr ecor dsequent iall
ywi thint hebl ock.
d)Modi ficat ionofr ecor ds:Tomodi fyar ecord,f irstsear cht hatr ecordandt hen
modi fyi t.Updat edr ecor di sst oredatsameposi tionifithassamekeyv al
ueand
sizeequalt ot heor iginalr ecor d.Otherwi seor i
ginalr ecordi sdeletedandnewr ecord
i
si nser ted.
e)Del etionofr ecor ds:Todel et ear ecor d,f i
rstsear cht hatrecord.Speci f
iccodesar e
usedt oi ndicat edel et edr ecor ds.Recor dsconsi stsoff l
ags.Speci f
iccodei sinserted
tot hef l
agoft hatr ecor dt hatneedst obedel eted.
f)I nser tionofr ecor ds:Toi nser tar ecord, firstfindt hedesi redbl ockaccor di
ngt okey
value.Thenconf irmt hatr ecor ddoesnotexi stal ready .Ther ecordisf i
rstplacedi n
ov erflowar eaandt hencopi edt othedesi redbl ock.
Advant agesofI ndexsequent ial
- E fficientf i
lesy stem f ormedi um andl argesi zefil
es.
- E asyt oupdat e.
- E asyt omai ntai nt handi rectf il
es.
- E fficientuseofst oragespace.
- Se archi ngofr ecor dsar efast .
- Ma i
nt ainadv ant agesofsequent ialfil
esy stem.
Disadvant agesofI ndexsequent i
al
- I nef ficientf il
esy stem f orsmal l sizef i
les.
- I ti sexpensi vemet hod.
- Ty pical st ruct uret hansequent ial fi
les.
90
- I
ndexesneedaddi
ti
onalst
oragespace.
- Per
formancedegr
adat
ionwithrespectt
ogr
owt
hoff
il
es.
5.
3.4HashingTechniques
Hashi
ngisat echni
quebywhi chkeyfi
eldi
sconvert
edint
oaddr
essofphy
sicall
ocat
ion
orr
ecordbyusinganyf unct
ion,
knownashashfuncti
on.
Hashf uncti
on
Keyfi
eld Addr
essofr
ecord
42
01
12 9 Addr
ess
Boundar
yfol
ding.
i Shi
i ftf
oldi
ng:I
nthistechni
quevari
ouspart
sofkeyval
ueareshi
ft
edl
ater
all
y
ory
oucansaythattheyaresi
mplyaddedasshowni
nFigur
e.
24 86 10
86
10
120 Addr
ess
Shi
ftf
oldi
ng.
c)Div i
sionmet hod:Indi vi
sionmet hod,di vi
det hekeyvaluewi thanynumberandt ake
quotientasaddr essoft hatrecord.Most l
yprimenumberi st akenasdi vi
sor.Consi
dera
recordhav i
ngkeyv alue550whi chisdi v i
dedby5gi ves110asquot i
entwhi chi
staken
asaddr essofthatr ecord.
d)Div i
sion-
remai ndermet hod:Indi v
ision-remaindermethod,di vi
det hekeyv al
uewi th
anynumber( Primenumber )andt aker emai nderasaddressoft hatrecord.Thedivisor
mustbegr eatert hantotalnumberofr ecordsandsmal lthenal lkeyv al
ues.Suppose
thereare100r ecordsi nanyf i
le.Ar ecor dhaskeyv al
ue660whi chi sdivi
dedby109
gives6asr emai nderwhi chistakenasaddr essofthatr
ecor d.
91
e)Radi xt ransf ormat i
on met hod (Radixconv er sion met hod):I nr adixconv ersion
met hod, f
irstkeyi sconv ertedint obinaryst ri
ng.Thent hisst ri
ngi spar ti
tionedi ntosmal l
stri
ngs.Thent hesest ri
ngsar econv ertedint odeci mal format .
Suppose,ar ecordhaskeyv alue269whosebi nar yequi v alenti s100001101.Take
smal lst r
ingsof3bi tseach.Thesear e100,001,101.Now conv ertt hem i nto
decimal formatwhi chgi ves4, 1,5.Thesedi gi tsaret reatedasnumber swi thr adixr .
2 1 0
Supposeri s5.Thenaddr essi s4×5 +1×5 +5×5 =110
f) Pol ynomi alconv er
sionmet hod:I npoly nomi alconv ersionmet hodev erydi gitofkey
valuei stakenascoef ficientofpol ynomial.Af terobt ai
ningt hatpol y nomi al,dividei tby
anot herpoly nomi al.Ther emai nderpol ynomi al givest hebasi sofaddr essoft hatrecor d.
g)Tr uncat i
onmet hod:I nt runcat i
onmet hod,somedi gi
tsofkeyv aluear et runcat ed.
Theymaybel eftmostdi gits,rightmostdi gitsorcent raldigits.Ther emai ni
ngdi gi
t sar e
taken asaddr essofr ecor d.Supposear ecor di shav i
ng keyv al ue543189.Then
truncatef i
rsttwol eftmostdi gits,whichgiv es3189asaddr essf ort hatr ecor d.
h)Conv ersionusi ngdi gitalgat es:Inthismet hod, conv ertkeyv aluei ntobi nar yformatt hen
applydi ff
erentoper ati
onsont hesedi git
sandatl astconv ertt her esultint odeci mal format
asf oll
ows
269 100 001 101
AND OR NAND
oper
ati
on operat
ion oper
ati
on Addr
essofr
ecor
d
0 1 1 2
Fi
gConv
ersi
onusi
ngdi
git
algat
es.
5.3.
4. 1.Colli
sionandSy nony ms
Themai ndi sadv antageofhashi ngi scolli
sion.
Collision:Acol li
sionoccur swhenahashf unctionfmappedmor ethanonekeyv alue
i
ntosamephy sicaladdr ess.
Synonym:Thekeyswhi char emappedi ntosamel ocationar eknownasSy nony ms.
Consi dert hef oldingmet hodi nwhi chkey248610gi vesaddr ess129andkey925005
al
sogi vesaddr ess129.Thi sisacol l
isionandkey248610and925005ar esynonyms.
5.3.
4. 2.Techni quest oAv oidCollisions
Ther ear et womai ncol l
isionresol utiontechni que:
(i)OpenAddr essing
(ii)Ov er fl
owChai ni
ng.
Botht echniquesar ebasedont hef actt hatincaseofcol li
sion, t
hesynonym keyr ecord
i
swr iteonanot herl ocation.
i)OpenAddr essi ng:Inopenaddr essing,thenex tfr
eeorempt yposi
tionissearchedt o
stor
esy nony m keyr ecor d.Ifther ei snoempt yposi t
ionwi thinabl ockthenempt y
posi
t i
on i n nextbl ock i s searched.Ther e arev ari
ous pr obing methods in open
addressi ngbutt hesi mpl estonei sl inearpr obing.
a)Li nearpr obi ng:Li nearpr obi
ngi st hesi mpl esttechni quewhi chisbasedoncy cli
c
92
problem sequence.Suppose,therearet alnl
ot ocat
ionsinablock.Supposeakeyki s
mappedi ntolocatondwhi
i chisnotempt ythenthesear ngsequencebecomesd,
chi
d+1, d+2,d+3, ..
.,n,1,2,3,.
..
,d–1
I
fthereisnof reel
ocationinthatblockthen,
startsearchi
nginnextconsecuti
veblock.I
t
i
salsoknownasConsecut iveSpil
lMethod.
Considertheexampl eofr el
ati
onEmpl oyee(Dept-I
D,Name)wher eDept -
IDiskeyfiel
dfor
mapping.
Employee
Dept -I
D Name
1 Anand
2 Rakesh
3 Pi
yush
2 Deepak
2 Manoj
Bl
ock-
I Bl
ock-
II
Locat
ionNo. Dat
a Locat
ionNo. Dat
a
1 Anand 5 Manoj
2 Rakesh 6
3 Pi
yush 7
4 Deepak 8
Li
nearpr
obi
ng.
Fi
g
-Forempl
oyeeAnand,
Dept
-I
Dismappedi
nto1.
-Forempl
oyeeRakesh,
Dept
-I
Dismappedi
nto2.
-Forempl
oyeePi
yush,
Dept
-I
Dismappedi
nto3.
-Forempl
oyeeDeepak,Dept
-I
Dismappedi
nto2.Acol
l
isi
onoccur
sbecausel
ocat
ion
2i snotempt y.So, sear chingi sst artedf r
om l ocation3.Locat i
on4i sempt ywhichis
gi ventoDeepak.
-F orempl oyeeManoj ,agai nDept -I
Di smappedi nto2.A col li
sionoccur sbecause
location2i snotempt y.So, sear chingi sstartedf oranempt ylocat i
on.Her eBlock-
Iis
fullsosear chi
ngi sst art
edi nconsecut ivebl ock,Block-I
Iandl ocat ion5i sgi v
ent o
Manoj .
Di sadvant agesoflinearpr obi ng
- Cr eati
onofcl ust erofr ecor ds( cl
usteri
ngef f
ect )
.
- Se archingti
mef orfreel ocat i
oni smor e.
b)Rehashi ng:To avoi d clust er i
ng ef f
ecti nl i
nearpr obi
ng mor et han onehashi ng
f uncti
onscanbeused.I ff irsthashf uncti
onr esultscolli
si ont henanot herhash
f uncti
oni susedt or esolv ecol l
ision.Butt hi
smet hodr esult
sext r
aov erhead.
i
i)Ov erf
low Chaining:I nt hismet hod,t herear et woar easf orst oringr ecords,primary
areai nwhi chrecordi sst oredi nnor mal condit
ions, i
fanycol l
isionoccur sthensy nonym
keyr ecordi sstor
edi nov erfl
owar ea.
Consi dert heexampl eofr elat i
onempl oyeeshowni nthepr eviousf i
gure.Now t he
empl oyeeDeepakandManoj ar est oredasshowni nt hefol
lowingFi gure.
93
Locat
ionNo. Dat
a Locat
ion No. Dat
a
1 Anand 5 Deepak
2 Rakesh 6 Manoj
3 Piy
ush 7
4 8
Pr
imar
yar
ea Ov
erf
low ar
ea
Advant
agesofover
fl
owchai
ning
- Lesssear chingti
mer equi
red.
- Noc l
uster i
ngeffect
.
- Mo r
eefficientthanopenaddressi
ngmet
hod.
5.3.5DirectFi leOr gani zati
on
Tomeett her equirementt oaccessr ecordsr andoml ydi r
ectf i
leor ganizat i
oni sused.In
directfi
leor ganizationr ecordscanbest oredany wherei nst oragear eabutcanbe
accesseddi rectly,wi thoutanysequent ialsear ching.Itov ercomest hedr awbacksof
sequential,indexsequent i
alandB- tr
eesf il
eor ganizati
on.Foranef fi
cientor gani
zati
on
anddi r
ectaccessofi ndividualr ecord,somemappi ngort ransf ormat ionprocedurei s
neededt hatconv ert
skeyf iel
dofar ecordi nt
oi tsphy sicalst oragel ocat i
on.Actually
,
directfil
eor gani zat
ion dependsupon hashi ng t hatpr ovidest hebaseofmappi ng
procedure.
Toov ercomet hedr awbacksofhashi ngal gor i
thm,col li
sionr esoluti
ont echniquei s
needed.Dev icest hatsuppor tdirectaccessar eCD’ s,Floppyet c.Di rectf i
leorgani
zati
on
i
sal soknownasRandom Fi l
eOr ganization.Choi ceofhashi ngal gor i
thm andcol li
sion
resolut
iont echni quei scr ucialpointindirectfil
eor ganization.
5.3.
5.1.Fi l
eOper ati
onsonDi rectFi l
es
(a)Creat i
ngadi rectf i
le:Af t
ersear chingandal locat i
ngf reespacef orf i
le,necessar y
entriesi nsy stem directoryar emade.I ndi rectf i
leor ganization,ahashi ngal gori
thm
formappi ngpr ocedur eandanycol li
sionr esolutiont echni quet oav oidcol l
isi
ons
duringmappi ngar especi fied.Thekeyf iel
di sal sospeci fied(Itmaynotbepr i
mar y
key).
(b)Openanexi st
ingfileandcl osi ngaf il
ear esameasi notherf il
eorgani zations.
(c)Sear ching( Readingorr etrieving)f rom directf il
e:Tor eadanyr ecor df rom directfile,
j
ustent ert hekeyf ieldoft hatr ecord.Wi tht hehel pofhashi ngalgor ithm thatkeyf i
eldis
mappedi ntophy sicallocationoft hatrecor d.Incaseofanycol li
sion, coll
isionresolution
techniquei sused.
(d)Updat ionofr ecordsi ndi r
ectf i
le:
() Addi
i nganewr ecor d:Toaddanewr ecor di ndirectf il
e,speci fyitskeyf iel
d.Wi th
thehel pofmappi ngpr ocedur eandcol l
isionr esol uti
ont echni que,gett hef ree
addr essl ocationf orthatr ecord.
(i
i) De leti
ngr ecordf rom di rectfil
e:Todel etear ecord,firstsearcht hatrecor dand
aftersear ching, changei tsstatuscodet odel etedorv acant.
(i
i)Modi
i fyanyr ecor d:Tomodi fyanyr ecord,f i
rstsear cht hatrecor d,thenmaket he
94
necessar ymodi fications.Thenr e-wr i
t ethemodi f
iedr ecordtot hesamel ocation.
Advant agesofdi rectf iles
- Recor dsar enotneededt obesor t
edi nor derdur ingaddi t
ion.
-I tgi vesf ast estr etriev alofr ecords.
-I tgi vesef f
icientuseofmemor y.
- Oper at i
onsondi rectf i
lear ef astso t her eisno need t o collectsamet ypeof
oper at i
onsi naf il
e, asi nsequent ialfil
esy st em.
- Sear chingt i
medependsuponmappi ngpr ocedurenotl ogar i
thm oft henumberof
sear chkey sasi nB- trees.
- Suppor tsfastst oragedev ices.
Di sadvant agesofdi rectf i
les
- Wa st ageofst or agespace( Clustering)i fhashingal gorit
hm i snotchosenpr oper l
y.
-I tdoesnotsuppor tsequent ialstoragedev i
ces.
- Di rectf il
esy stem i scompl exandhenceexpensi ve.
-E xtraov erheadduet ocol l
isionresol utiont echniques.
5.4 I ndexi ng
Ani ndexi sacol lectionofdat aent ri
eswhi chisusedt ol ocat ear ecordi naf il
e.I ndex
tabler ecor dsconsi stoft wopar ts,thef i
rstpar tconsi st
sofv alueofpr imeornon- prime
attribut esoff i
ler ecor dknownasi ndexi ngf i
el dand, t
hesecondpar tconsi stsofapoi nter
tot hel ocat i
onwher et her ecor disphy sicall
yst oredinmemor y.Ingeneral ,i
ndext ablei s
l
iket hei ndexofabookt hatconsi stsoft henameoft opicandt hepagenumber .Dur i
ng
sear chi ngofaf i
l
er ecor d, i
ndexi ssear chedt olocatet herecor dmemor yaddr essi nstead
ofsear chi ngar ecor di nsecondar ymemor y.
Ont hebasi sofpr oper tiest hataf fectt heef fi
ciencyofsear chi
ng,t heindexescanbe
classi fiedi ntot wocat egor i
es:
1.Or deredi ndexi ng
2.Hashedi ndexi ng.
5.4.
1Or deredI ndexi ng
I
nor deredi ndexing, recordsoff i
l
ear est oredinsomesor tedor derinphy si
calmemor y
.
Thev aluesi nthei ndexar eor dered( sorted)sot hatbinar ysearchcanbeper formedon
thei
ndex .Or deredi ndexescanbedi videdi ntotwocategor i
es.
1. Dense
i
ndexing 2.Sparse
i
ndexing.
5.4.1.1DenseandSpar seI ndexing
Densei ndex:I ndensei ndexingt hereisar ecordi ni ndextablef oreachuni que
val ueoft hesear ch-keyat tr
ibuteoff i
l
eandapoi nt ertothef i
rstdat arecordwith
thatv alue.Theot herr ecordswi tht hesamev alueofsear ch-keyat tr
ibut
ear e
st oredsequent i
all
yaf terthef irstrecord.Theor derofdat aentriesi ntheindex
dif f
er sfrom theor derofdat arecor dsasshowni nt hef ol
lowingFigur e.
Advant
agesofDensei
ndex
95
- I
tiseff
ici
enttechni
queforsmallandmedium si
zeddat
afi
l
es.
- Sear
chingiscomparat
ivel
yfastandeff
ici
ent
.
Di
sadvant
agesofDensei
ndex
- I
ndextablei
slargeandrequi
remorememor yspace.
- I
nsert
ionanddeleti
oniscomparat
ivel
ycomplex.
- I
n-ef
fi
cientf
orlargedat
afil
es.
Search-
key
att
ri
bute Name Age Sal
ary
Ami
t
Ami
t 22 5000 Ami
t
Sandeep
Sear
ch-
key Ami
t 21 6000 Sonal
val
ue Sonal
Sandeep 30 8000 Spar
sei
ndex
John Sandeep 35 2500
Densei
ndex
Sandeep 20 10000
Sonal 24 20000
Sonal 28 15000
John 40 6000
John 31 18000
Fi
g Denseandspar
sei
ndex.
Sparseindex:Oncont rary
,i nspar sei
ndexingt hereareonlysomerecordsi nindextable
foruniquevaluesofthesear ch-keyattri
buteoff il
eandapoi ntert
othef irstdatarecord
withthatval
ue.Tosear char ecordi nsparseindexwesear chforavaluet hati
sl essthan
orequaltov alueinindexf orwhi chwear elooking.Aft
ergetti
ngthefirstrecord,li
near
searchisper
formedt oretr
ievethedesi r
edr ecord.Therei
satmostonespar seindexsince
i
tisnotpossibletobuil
daspar sei ndexthatisnotcluster
ed.
Advant
agesofSpar
sei
ndex
- I
ndextabl
eissmal
l andhencesav
ememor yspace(
especi
all
yinl
argef
il
es)
.
- I
nser
ti
onanddelet
ioniscomparat
ivel
yeasy
.
Di
sadvant
agesofSpar
sei
ndex
- Sear
chi
ngiscompar
ati
vel
yslower,si
ncei
ndext
abl
eissear
chedandt
henl
i
near
sear
chi
sperf
ormedi
nsi
desecondarymemor
y.
5.
4.1.2ClusteredandNon- ClusteredI
ndexes
Clusteredindex:I nclusteri
ng,indexfi
lerecordsar estor
edphy sicall
yinorderona
non-primekeyat tri
butet hatdoesnothav eauni quevaluef oreachr ecord.The
nonpr i
mekeyf ieldisknownascl ust
eri
ngfieldandindexinknownascl ust
eri
ngi ndex.
Itissameasdensei ndex.Af il
ecanhav eatmostonecl uster
edi ndexasi tcanbe
cluster
edonatmostonesear chkeyattr
ibute.Itmaybespar se.
Non- cl
usteredindex:Ani ndext hati
snotclusteredi
sknownasnon- clust
eredindex.
Adatafil
ecanhav emor ethanonenon- cl
usteredindex.
5.
4.1.3Pri
mar yandSecondaryIndex
Primaryindex:Apr i
maryindexconsist
sofal lprime-
keyattri
butesofat ableanda
pointert
ophy si
calmemoryaddr essoftherecordofdatafi
le.Tor et
ri
evear ecordon
thebasisofal lpri
marykeyat t
ribut
es,pri
mar yindexisusedf orfastsearching.A
96
bi
narysear
chi
sdoneonindextabl
eandt
hendi
rect
lyr
etr
iev
ethatr
ecor
dfr
om
physi
cal
memor
y.I
tmaybespar
se.
Advant
agesofPr
imar
yindex
-Sear
choper
ati
oni
sver
yfast
.
-I
ndext
abl
erecor
disusual
l
ysmal
l
er.
-Apr
imar
yindexi
sguar
ant
eednott
odupl
i
cat
e.
Di
sadvant
agesofPr
imar
yindex
- Thereisonl yoneprimar yindexofat able.Tosear char ecordonlessthanallpri
me-
keyattri
butes, l
i
nearsear chisper f
ormedoni ndext able.
- To c r
eateapr i
mar yi ndexofanexi st i
ng table,recordsshould bei nsome
sequentialorderotherwisedat abaseisrequiredtobeadj ust
ed.
Secondar yindex:Asecondar yindexpr ovidesasecondar ymeansofaccessi nga
datafil
e.Asecondar yindexmaybeonacandi datekeyf ieldoronnon- pri
mekey
att
ri
butesofat abl
e.Tor etr
ievear ecordont hebasi sofnon- pr
imekeyat t
ri
butes,
secondaryindexcanbeusedf orfastsearching.Secondar yindexmustbedensewi t
h
aindexent r
yf oreverysearchkeyv al
ueandapoi ntert oeveryrecordi
naf i
l
e.
Advant
agesofSecondar
yindex
- I
mpr ovesearchti
meifsearchonnon- pri
mekeyat t
ributes.
- Ad atafi
lecanhavemorethanonesecondar yi
ndex.
DisadvantagesofSecondaryi
ndex:Themaj ordi
sadvantagesofsecondar
yindexar
e:
- As econdaryi
ndexusual
lyneedsmor est or
agespace.
- Se archtimeismorethanprimaryindex.
- Th eyi mposeasi gni
fi
cantov er
headont hemodi f
icati
onof
database
Fi
g.Pr i
mar yandsecondaryindex.
5.
4.1.4SingleandMul t
ilevelI
ndexes
Singlel
evelindexes:Asi ngl
est ageindexforadat af
ilei
sknownassi ngl
el ev
elindex.
Asinglelevel i
ndexcannotbedi vided.I
tisusefuli
nsmal landmedium si
zedat afil
es.
Ifthef il
esi zeisbi gger,then singlelevel
,indexi
ng isnotan ef fi
cientmet hod.
Searchingisfastert
hanot herindexesforsmall si
zedatafil
es.
Multil
evelindexes:Asi ngl
eindexf oralargesizedatafil
eincr
easesthesizeofindex
97
tableandi ncr easest hesear chtimet hatr esult
si nslowersear ches.Thei deabehi nd
mul t
il
ev eli
ndexesi st hat,asi nglelev elindexi sdividedi nt
omul tiplel evels,whi ch
reducessear chtime.
Inmul t
il
ev eli
ndexes, thef i
rstlevelindexconsi stsoft wof iel
ds,thefirstf i
eldconsi stsof
av al
ueofsear chkeyat t
ributesandasecondf iel
dconsi stsofapoi nt ertot hebl ock( or
secondl eveli
ndex)whi chconsi ststhatv aluesandsoon.
Tosear char ecor dinmul ti
leveli
ndex ,binar ysearchisusedt ofi
ndt hel argestofal lthe
smallv aluesorequalt ot heonet hatneedst obesear ched.Thepoi nterpoi ntst oa
blockoft hei nneri ndex.Af terreachingt ot hedesi r
edbl ock,thedesi r
edr ecordi s
searched( incaseoft wo-levelindexing)ot herwiseagaint helar
gestoft hesmal lvalues
orequal totheonet hatneedst obesear chedandsoon.
Benefitsofmul t
il
ev elindexesar etheyr educesear cht i
mesi gnifi
cant lyforl argesi ze
datafil
es.
I
D Name Age Sal
ary
Field Bl ock
value poi nt
er
1
2
3
4
First level
i
ndex
Blocks
(Second l
evel i
ndex) Dat
a f
il
e
Fi
g.Mul
ti
lev
eli
ndexi
ng.
5.4.
2HashedI ndexing
Toov ercomet hedisadv antagesofor deredindexing,ahashindexcanbecr eat
edf ora
dataf i
le.Hashingal low ust oav oidaccessingani ndexst ructur
e.A hashedi ndex
consistsoftwof i
elds, t
hef ir
stfieldconsist
sofsear chkeyattri
butev al
uesandsecond
fi
eldconsistsofpoi ntertot hehashf il
est r
uctur
e.Hashedi ndexingisbasedonv alues
ofrecordsbeingunifor mlydistr
ibutedusingahashedf uncti
on.
5.5 B- tr
eeIndexf il
es
InB-Treeindexfil
es, t
reest ruct
ur eisused.AB- t
reeoforderm i sanm- waysearcht r
ee
withthefoll
owingpr operties.
1.Eachnodeoft
het
ree,
exceptt
her
ootandl
eav
es,
hasatl
east[ ]subt
reesandno
mor et hannsubt r
ees.I
tensurest
hateachnodeoft reeisatl
easthalffull
.
2.Ther ootoft hetr
eehasatleasttwosubtrees,unl
essitisit
sel
faleaf.Itforcest
hetreet
o
branchear ly
.
3.Alll
eav esoft het
reeareonthesamelevel
.Itkeepsthetreenearl
ybalanced.
Toov ercomet heperf
ormancedegradat
ionwi t
hr especttogrowthoff i
lesinindex
98
sequent i
alfil
es B-
Tree i
ndex fi
l
es ar
e used.Itis a ki
nd ofmul t
il
eveli ndex f
il
e
organizati
on.
Intreestruct
ure,
searchst
art
sfrom t
herootnodeandst
opsatl eafnode.
(i
)Non- LeafNode:
P1 R1 K1 P2 R2 K2 Pm-1 Rm-1 Km-1 Pm
Innon-
leafnode,ther
earetwopoint
ers.Poi
nterPipoint
stoanyot hernode.Poi
nterRi
poi
ntstotheblockofactualr
ecor
dsorst or
ageareaofr ecords.Kir
epresent
sthekey
val
ue.
(i
i
)LeafNode:
P Pn-1 Kn-1 Pn
1 K1 P2 K2
Inleafnode,ther
ei sonlyonepoint
erPiwhichpoi
ntstoblockofactualr
ecordsor
stor
ageareaofrecords.Kir
epr
esent
sthekeyv
alue.AB-
tr
eeforfi
leempl
oyeeisshownin
thefoll
owi
ngfigure
Gaur
av Nav
een
Gaurav Naveen
bucket bucket
Amar Chi
rag Har
ish Lal
i
t Pr
aveen
Amar Chi r
ag Hari
sh Lali
t Praveen
bucket bucket bucket bucket bucket
Fi g.B- tr
eef orfil
eempl oy ee.
Oper ationsonB- TreeI ndexf iles
- Se ar chingar ecor d:Sear chi ngar ecor dwi thi tskeyv aluestart
sf r
om rootnode.Itis
possi bletof inddesi redr ecor dwi thoutgoi ngt oleafnodei nB- t
ree.
- De let i
onofar ecor d:Del et ioni nB- t
r eei sacompl icat edprocess.Ifdesiredentryis
i
nl eafnode, then, simpl ydel eteitot her wisef indapr operreplacementfort hatentr
y.
- I nser ti
onofar ecor d:B- treei sabal ancedt reeandi nser
tionofanewr ecordinB-
treecausenodespl itsandt her eforeaf fectst hehei ghtoft het r
ee.
Advant agesofB- treei ndexf iles
- Ke yv alueappear sonl yoncei nt henode.
- Se ar chingi sf astert hani ndexedsequent i
al fi
l
es.
- Pe rfor mancei smai ntainedw. r.
t.growt hoff il
esize.
Disadvant agesofB- treei ndexf iles
- Up dat i
onofr ecor dsar emor ecompl icat edt henB+t rees.
+
- L essef fi
cientt hanB t r
eesanddi r
ectf iles.
- Se ar chingt i
mei sst il
l propor tional t
ol ogar ithm oft henumberofsear chkey s.
+
5.
6 B–t r
eeI ndexf iles
+
AB- tr
eei saki ndofbal ancedt ree.Thel engt hofev erypat hfrom rootofthet reetothe
l
eafoft het reear esame.Thenumberofchi ldrenni sf ixedforapar ti
culartree.Each
99
non-leafnodei nthetreehasbet ween( n/2)andnchildr
en.IndexusedinB+-
treefi
lesis
mul t
ilevelindexbuti t
sstructur
ediff
erf rom thei
ndexstructur
eusedinmulti
leveli
ndex-
+
sequent ialfi
les.At ypi
calnodeofB- t
reecontai
nsupt on–1sear chkeyv al
uesand
pointers.Kir epresentssearchkeyv alueandPir epresentspoint
ertoaf i
l
er ecor
d,as
showni nFigureasf oll
ows.
Pn–1 Kn–1
P1 K1 P2 K2 Pn
Fig.TypicalnodeofaB+-tree.
+
InB- tr
eessear chkeyv aluesar einsortedorder,
thus,fi<j
i ,t
henKi<Kj.Thenumberof
pointersinanodei scaledFanoutoft
l henode.
() L
i eafnodes:I nal eafnode,apoi nterPipointstoeitheraf i
lerecor
dhav i
ngsearch
keyv alueKiort oabucketofpoi nter
swher eeachpoi ntertoaf il
erecordwith
searchkeyv alueKi( I
ncaseofsecondar yi
ndexinwhi chindexismadeofnonpr i
me
keyat t
ributesandf il
ei snotsor tedinsearchkeyv alueorder).Aleafnodeforfil
e
Empl oyee( I
D, Name, Salar y
)isshowni nFi
gureasfollows.
() No
i
i n-l
eafnodes:Thest ructureofnon- l
eafnodesar esameasofl eafnodewitha
singledifferencet hatpoi nterPipointstothetreenodes.I tcontai
nsatl n/
east( 2)
pointer
sandamaxi mum ofnpoi nters.
Adi
tya James
A1 Adit
ya 20000
A6 James 30000
A2 James 15000
Empl
oyeef
il
e
Fi g.AleafnodeofB+- t
reewi thindexn=3.
(i
i
i) Ro otnodes:Ar ootnodecont ai
nsatleast2poi nter
sandamaxi mum oflessthan
+
[n/2]pointers.AB- tr
eecont ainsonlyasi nglenodei frootnodeconsistsonlya
singlepointer.
Apoi nterPiwi t
hasear chkeyv alueKiinanon- leafnodepoi nt
st oapartofsubt r
ee
havingsear chkeyv aluesl esst hanKi,andgr eatert hanorequalt oKi– 1.Poi
nterPm
pointst oapar tofsubt r
eehav ingsearchkeyv aluesgr eat
erthanorequalt oKm – 1,
PointerP1poi ntstothepar tofsubt reehavi
ngsear chkeyv al
ueslesst
hanK1.
Har
ish
Gaur
av Lal
i
t
Amar Chi
rag Gaur
av Har
ish Lal
i
t Nav
een
+
FI
GURE B-
tr
eef
orf
il
eempl
oyee.
100
OperationsonB+-Tr eeindexf i
les:
- Se ar chingar ecord:Sear chingar ecordwi t
hi tskeyv al
uestart sfrom rootnode.Itis
+
possi blet ofinddesi redr ecor dwithoutgoingt oleafnodei nB- t
ree.
+
- De let i
onofar ecord:Del etioninB- t
reeiscompl icatedprocessi nsomespeci al
cases.I fdesi r
ed ent ryi si nleafnode t hen,si mpl ydeletei tand i fbucketi s
associ atedt henbucketbecomesempt yasar esul
t.Ifdeleti
oncausesanodet obe
less t han hal ff ull
,t hen iti s combi ned wi thits neighbor i
ng nodes and i tis
propagat edal lt
hewayt ot her oot
.
- Inser ti
onofar ecord:Toi nsertanewr ecordi nB+-
tree,fi
rstsear chal eafnodewi th
samesear chkeyv alue.Si mpl yaddanewr ecordtof i
leoraddapoi nterinbucket ,
whi chpoi ntst other ecor d.Ifsearchkeyv aluedoesnotappear ,si
mpl yinsertthe
valuei nl eafnodei ncor rectposi ti
onorcr eateanew bucketwi ththeappr opri
ate
point erifnecessar y.
agesofB+-
Advant tr
ees
- I
tprovi
desareasonabl
eperfor
mancefordi
rectaccess.
- I
tprovi
desanexcell
entper
formancef
orsequenti
alandrangeaccesses.
- Sear
chingi
sfaster
.
Di agesofB+-
sadvant tr
ees
- I
nserti
onismorecomplexthanB-
tr
ees.
- Deleti
onismorecomplext
hanB-t
rees.
- Searchkeyval
uesaredupl
i
catedwhichresul
tsi
nwast
ageofmemor
yspace.
5.
7 comparisonofdif
fer
entf
il
eorganizat
ions
Themai
ndi
ff
erencesbet
weenvari
ousfi
leorgani
zat
ionsar
easf
oll
ows:
No. Sequent
ial I
ndexed Hashed/
Dir
ect
1. Random r
etr
ieval
onpr
imar
y Random r
etr
iev
al ofpr
imar
y Random r
etr
iev
alof
keyisi
mpracti
cal
. keyismoder
atelyfast
. pri
marykeyi
sv er
yfast
.
101
2. Therei
snowast
edspacef
or Nowastedspacefordat
a Ext
raspacef
oraddi
ti
on
data butt
herei
sextraspacef
or anddel
eti
onofr
ecords.
i
ndex.
3. Sequenti
alr
etr
iev
alonpr
imar
y Sequent
ial
retr
iev
alon Sequential
retr
iev
alof
keyisver
yfast
. pri
marykeyismoderat
ely pri
mar ykeyis
fast
. i
mpr acti
cal.
4. Multi
plekeyret
ri
eval
in Mul
ti
plekeyr
etri
evalisver
y Multi
plekeyret
ri
eval
is
sequenti
alf
il
eorgani
zati
oni
s f
astwi
thmulti
pleindexes. notpossibl
e.
possi
ble.
5. Updatingofr
ecordsgeneral
l
y Updat
ingofrecordsrequi
res Updati
ngorrecor
dsi
s
requi
resrewr
it
ingthefi
le. maint
enanceofindexes. theeasi
estone.
6. Addit
ionofnewrecords Addit
ionofnewr ecordsi
s Addit
ionofnewr
ecor
ds
requi
resr
ewrit
ingthefi
l
e. easyandr equi
res i
sv er
yeasy.
maintenanceofindexes.
7. Del
eti
onofrecor
dscancr
eat
e Delet
ionofrecor
dsiseasyi
f Del
eti
onofr
ecor
dsi
s
wast
edspace. spacecanbeal l
ocat
ed ver
yeasy
.
dynamical
ly
.
5.
8 Factorsaff
ecti
ngchoiceoffi
leor
gani
zat
ion
Themaj
orf
actor
sthataf
fectthechoi
ceoff
il
eorgani
zat
ionar
easf
oll
ows:
- Accesst
ype:I
nor
dert
osear
char
ecor
d,whet
herr
andom accessorsequent
ial
access
i
srequi
red.
- Accesstime:Thetot
alt
imetakenbyfil
eorganizat
iontof
indapart
icul
arrecor
d.
- Fi
lesize:Choi
ceisal
sodependentuponfi
l
esi ze.I
ffi
lesi
zeisl
argethenchoosedi
rect
accessot
her
wisechoosesequent
ial
access.
- Over
head:Each t
echni
quehassomeov
erhead (
itmaybespaceov
erhead,t
ime
overheadet
c.)
.Anyt
echni
quegi
vi
ngf
astaccessmaywast
emor
espacet
hensl
ower
techni
ques.
- Updat
ion t
ime:Ti
me r
equi
red t
o add,del
ete and modi
fyanyr
ecor
d al
so pl
ays
i
mpor
tantr
olei
nef
fi
ciency
.
- Compl
exi
ty:I
ftechni
quei
sfastt
heni
tiscompl
exandexpensi
ve.Whet
herf
undsar
e
av
ail
abl
etoadoptnewt
echni
ques.
- Avai
labi
li
tyofhar
dwar
e:Thehar
dwar
ethatsuppor
tsf
il
eor
gani
zat
ion.Exampl
etape
r
eadersuppor
tsonl
ysequent
ial
fil
eor
gani
zat
ion.
REVI
EW QUESTIONS
1.Aprimaryindexisbestsuit
edt
owhichall
ofthef
oll
owi
ng:
A.Findafewr ecor
dshavingaspeci
fi
ckeyval
ue
102
B. Fi ndal lrecor dsi nagi venr angeofsear chkeyv alues,wher etheremaybe
manymat chi ngr ecor ds
C. Fi ndmanyr ecor dswi thaspeci fi
ckeyv al ue D.Al loftheabov e
2.Whi chi st hebestf i
leor gani zat ionwhendat aisf requent lyaddedordel etedf r
om
af i
le?
A.Sequent i
al C.Di rect
B.I ndexsequent ial D.Noneoft heabov e
3.Ani ndexi scl ust ered, if
A. i tisonasetoff ieldsthatf or m acandi dat ekey
B.i tisonasetoff i
eldst hati ncl udet hepr i
mar ykey
C. t hedat ar ecor dsoft hef il
ear eorgani zedi nt hesameor derast hedat aentriesof
thei ndex
D.Thedat ar ecor dsoft hef il
ear eor gani zednoti nthesameor derast hedat aent r
iesof
thei ndex.
4.Acl uster i
ngi ndexi sdef inedont hefieldswhi char eoft y pe
A.Non- keyandor der i
ng C.non- keyandnon- order ing
B.keyandor der ing D.keyandnon- or dering
5.AB- treeofor der4i sbui ltfrom scr at chby10successi vei nser t
ions.Whati sthe
maxi mum numberofnodespl ittingoper ationst hatmayt akepl ace?
A.3 B.4 C.5 D.6
6.Consi deraB+t reei nwhi cht hemaxi mum numberofkey si nanodei s5.Whati s
themi nimum numberofkey sinanynon- rootnode?
A.3 B.4 C.5 D.6
7.Indexes_ __ _
_ __ ____ _.
A. Al lowr api dr etrievaloft abl es C.al lowr apidr etri
evalofr ecords
B. Pr ov ideanef fi
ciental ternat ivetosor ting D.bot hBandC
8.Li nearHashi ng
A.suppor tst heef ficientr eadi ngoft hef il
ei nor derbykeyv alue
B. doesnotmai ntainov er f
lowchai ns
C. hasamaxi mum successf ul searchcostof1bucket
D.Noneoft heabov e.
9.Consi dert hei nser ti
onofar ecor dint oaLi nearHashf il
et hatst artedwi th1bucket
wher ecur rent l
yt henextbuckett ospl i
ti snumber4andt henumberoft imest hef il
e
hasdoubl edi s7.I fthekeyv al ueoft her ecor di s601,t henwhatbucketshoul dstore
thisrecor d?
A. 5 B.255 C.89 D.11
10.Extendi bleHashi ng
A.usesandi rect or y C.does notmai ntain ov er
fl
ow
chai ns
B. hasaonedi sk- accesssear chcosti fdir ector yfi
tsi nmemor y D. al loft he
abov e
103
11.Thedi fferencebet weenadensei ndexandaspar sei ndexi sthat
A.adensei ndexcont ai nskey sandpoi nter sf orasubsetoft her ecordswher eas
aspar sei ndexcont ainskey sandpoi nt er sforev eryrecord
B.adensei ndexcanonl ybeapr imar yindexwher easaspar sei ndexcanonl ybe
asecondar yindex
C. adensei ndexcont ainskey sandpoi nt er sf oreachr ecordwher easaspar se
i
ndexcont ainskey sandpoi nt ersf orasubsetoft her ecords
D.nodi ffer enceatal l
12.Recor dsi naf i
lemaybev ariablel engt hbecause
A.t hesi zeofadat af ieldwi thint her ecor dmayv ary
B. af i
eldwi thi nther ecor dmayber epeat edav ar i
ablenumberoft i
mes
C.af ieldmayappeari nonl ysomeoft her ecor ds
D.Al l oft heabov e.
13.Thedi fferencebet weenf il
esst oringspannedv er susunspannedr ecordsisthat
A.af ilewi t
hspannedr ecor dswi llusel essdi skspacef orst oringr ecordsthan
wi t
hunspannedr ecor ds, ifani ntegr al numberofr ecordsdonotf i
tinablock
B.af ilewi t
hspannedr ecordscanhav er ecor dst hatar estor edonmor ethanone
diskbl ock
C. af il
ewi thspannedr ecor dsmustbeusedwhent hesizeofar ecordislargert
hanthe
blocksi ze
D.al loft heabov e
14.Whichoft hef ollowingr epresentpossi bl
ei ndexcombi nati
onsf oraf i
le?
A.onepr imar yi ndexandoneormor esecondar yi ndexes
B. onepr imar yindexandonecl ust er edi ndex
C.onepr imar yi ndex, onecl ust eredi ndexandonesecondar yi ndex
D.al loft heabov e.
15.Ifacol umnofat ablei sdesi gnat edasaf or eignkey ,thenitcanbeusedi na
A. pr imar yi ndex C.secondar yindex
B. Cl ust eringi ndex D.bot hBandC
16.Agr oupofphy sicalf ieldsst or edt oget heri nadj acentmemor yl ocat i
onsandr et
ri
eved
asauni tis
A.Logi cal r
ecor d C.phy sical recor d
B.Page D.DBcl ass.
17.Asetofi ndexesbui l
tuponanot hersetofi ndexesi scal l
ed
A.Indexpy rami d C.i ndexhi erar chy
B.Bi tmapi ndex D.si mpl ei ndex.
18.Anindexi susedi nrel ational dat abasesy stems
A.t oi mpr ovet heef fi
ci encyofnor mal i
zingr elations
B.t oi mpr ovet heef fi
ci encyofr etrievingt upl esf rom ar elati
on
C.t oi mpr ovet heef fi
ci encyoft heCr eat eTabl est atement
D.Noneoft heabov e.
104
19.
Whichoft hef oll
owingguarantee(s)theaccessst r
uct
ureisal way
sbalanced
whenalotofupdat essuchasi nserti
onsanddel eti
onsoff i
l
er ecor
dsoccur
?
A.M-WaySear cht ree C.Dynami chashi
ng
B.Multi
leveli
ndex D.B-t
reeandB+- tree
20.
Afact
ortoconsi derwhenchoosi ngaf i
leorganizat
ionis
A. Ef
fi
cientstorage C.fastdataretr
ieval
B.Securit
y D.alloftheabove.
CHAPTERSI X
RELATI
ONALALGEBRAANDCALCULUS
6.
1.I
ntr
oduct
ion
Relati
onalal gebraisoneoft het wo formalquer yl anguagesassoci at
ed withthe
rel
ationalmodel .I
tisaprocedurallanguage.Itspecif
iestheoperati
onst obeperfor
med
on existing rel
ati
onst o deri
ver esultrel
ati
ons.A sequenceofr elati
onalalgebrai
c
operationsformsar elat
ionalal
gebr ai
cexpression.Ther esul
toftherelat
ionalal
gebrai
c
expressionisalsoar el
ati
on.
Ther el
at i
onalalgebraisveryimportantduetomanyr easons.Fi
rstl
y,itpr
ovi
desabasic
foundation forr el
ati
onalmodeloper at
ions.Secondl y,itis used as a basi
sf or
i
mpl ement i
ngandopt i
mizingqueriesinRDBMS’ s.Thirdly,someoft hebasi
cconcepts
ofrelat
ionalalgebraareincorpor
atedintotheSQLl anguage.
Rel
ati
onalcal
cul
usi
saf
ormalquer
ylanguagewher
ethequer
iesar
eexpr
essedas
vari
ablesandf ormulasont hesev ariables.Thef ormul ausedi nr elati
onalcalcul
us,
describestheproper t
iesoft heresultr elat
iontobeobt ai
ned.Ther ei
snomechani sm t
o
specifyhowt hef ormulashoul dbeev aluated.Iti
sthesol er esponsi
bi l
ityoftheRDBMS
totransfor
mt hesenon- pr
ocedur alquer iesintoequiv
al ent,
ef f
ici
ent,
pr oceduralqueri
es.
Iti
sanon- procedur allanguage.Ther elationalcal
culusi saf ormallanguage,basedon
predicatecalculus.Rel at
ionalcal culusi sa combi ned term f ortupl ecalcul
us and
domai ncalcul
us.I ntuplecal cul
us,v ariablesrangeov ertuplesandi ndomai ncalcul
us,
vari
ablesrangeov ert
hedomai nsofat tributes.
6.2 Rel at ionalal
gebra
Relat
ionalal gebraisaproceduralquerylanguage.Itusesacol lect
ionofoper atorsto
composet hequer i
es.Everyoperatorinthealgebraacceptseitheroneort wor elat
ion
i
nstancesasar gumentsandout putaresult
antrelat
ioninst
ance.Thusoper ator
scanbe
composedeasi lytoconstr
uctcompl exqueri
es.Eachr el
ati
onalalgebraquerydescr i
bes
astep-by-
st epprocedureforcomput i
ngthedesiredanswer,basedont heorderinwhi ch
theoperator sareappl
iedinthequery.
Ther el
ati
onalal
gebrausesv ar
iouslogicalconnecti
ves[∧(and),∨(or
),¬(not)]and
compari
sonoperat
ors(<,<=,=,≠,>=,>)t oconstr
uctcomposi teandmor ecompl ex
queri
es.
Wedi scussthedif
fer
entoperators(
Basi csetorient
edoper ator
s—union,i
ntersecti
on,
di
ffer
ence,andCar
tesi
anproductandrelati
onaloperator
s—selecti
on,pr
oject
ion,divi
sion
105
andjoin)indetai
l
,withexampl
es,i
nsubsequentsecti
ons.Al
ltheexampl
esar ebasedon
theEMPLOYEE- STUDENTdatabaseshowninthefoll
owingFigur
e.Thi
sdatabasecontai
n
twoTabl esEMPLOYEEandSTUDENTandt herel
ati
onshi
pisthatanempl
oy eecanalsoa
studentandvicever
sa.
Employee Student
EI
D Name Sal
ary SI
D Name Fees
1E John 10,
000 1S Smi
th 1,
000
2E Ramesh 5,000 2S Vi j
ay 950
3E Smith 8,000 3S Gaur av 2,000
4E Jack 6,000 4S Ni le 1,500
5E Nil
e 15,000 5S John 950
Fig.Empl
oyeeandst
udentrel
ati
ons.
6.
2.1Oper
ati
onsi
nRel
ati
onal
Algebr
a
Ther el
ationalal gebraicoperati
onscanbedi videdintobasi
cset
-or
ient
edoperations
(uni
on,i ntersection,setdi f
ference,and Cart
esian pr
oduct
)and rel
ati
onal
-or
iented
operati
ons( selection,proj
ect
ion,divi
sionandj
oins)
.
6.
2.1.
1Basi
cSet
-or
ient
edOper
ati
ons
a)Th
( euni
onoper
ati
on:Theuni
onoper
ati
oni
sabi
nar
yoper
ati
ont
hati
susedt
ofi
nduni
onof
rel
ati
ons.Her
erel
ati
onsar
econsi
der
edasset
s.So,dupl
i
cat
eval
uesar
eel
i
minat
ed.I
tis
denotedby(
∪).
Condi
ti
onsf
oruni
onoper
ati
on:Ther
ear
etwonecessar
ycondi
ti
onsf
oruni
onoper
ati
on.
(
i) Bot
hther
elat
ionshav
esamenumberofat
tr
ibut
es.
(
i)Da
i t
aty
pesoft
hei
rcor
respondi
ngat
tri
but
esmustbesame.
Twor
elat
ionsar
esai
dtobeuni
oncompat
ibl
eift
heyf
oll
owt
heabov
etwocondi
ti
ons.
Ex.I
fyouwantt
ofi
ndt
henamesofal
lempl
oyeesandnamesofal
lst
udent
stoget
her
t
hent
hequer
yisπName(
Empl
oyee)∪πName(St
udent).
Ther
esul
tisasf
oll
ows
Name
John
Ramesh
Smith
Jack
Nil
e
Vij
ay
Gaurav
b)Se
( ti
nter
sect
ionoper
ati
on:Seti
nter
sect
ioni
susedt
ofi
ndcommont
upl
esbet
weent
wo
rel
ations.I
tisdenotedby( ∩).Ifyouwantt ofi
ndal ltheemployeesfrom Rel
ati
on
Empl oyeethosear
eal sostudents.Rul
esofsetunionoper at
ionsarealsoappli
cabl
e
here.Thenthequer
y,isπName(Employ
ee)∩ Name(
Student).Theresul
tis
106
Name
John
Smit
h
Ni
le
c)Se
( t
-di
ff
erenceoper
ati
on:Set
-di
ff
erenceoper
ati
oni
sabi
nar
yoper
ati
onwhi
chi
susedt
ofi
nd
t
uplest
hatarepresenti
noner
elat
ionbutnotinotherr
elat
ion.Iti
sdenot
edby(—).I
tremoves
t
hecommont upl
esoftworel
ati
onsandpr oduceanew relati
onhavi
ngrestoft
het upl
esof
f
ir
strel
ati
on.
Ex.I
fyouwantt
henamesoft
hoseempl
oyeest
hatar
enotst
udent
s,t
hent
hequer
y,i
s
πName(
Empl
oyee)—πName(St
udent).Ther
esul
tis
Name
Ramesh
Jack
d)Ca
( r
tesi
anpr
oductoper
ati
on:Car
tesi
anpr
oducti
sabi
nar
yoper
ati
onwhi
chi
susedt
o
combineinfor
mat
ionofanyt
worel
ations.Supposear
elat
ionR1ishavngm t
i upl
esand
otherr
elat
ionR2i
shavngnt
i upl
esthenR1×R2hasm ×nt upl
es.I
tisdenot
edby(X)
.
Consi
dert
hef
oll
owi
ngFi
gur
eCar
tesi
anpr
oductofr
elat
ionEmpl
oyeeandJobi
sshown
as
Quer
yis→ Empl
oyee×Job
Empl
oyee Job
EI
D Name JI
D JI
D Job
1E Manoj 1J 1J Tester
2J Manager
2E Deepak 2J
3E Vi
nay 1J
EI
D Name Empl
oyeeJI
D JobJI
D Job
1E Manoj 1J 1J Test
er
1E Manoj 1J 2J Manage
r
2E Deepak 2J 1J Test
er
2E Deepak 2J 2J Manage
r
3E Vi
nay 1J 1J Test
er
3E Vi
nay 1J 2J Manage
r
Resul
tofCar
tesi
anpr
oductoper
ati
on.
6.
2.1.
2Rel
ati
onalOr
ient
edOper
ati
on
a)Sel
( ect
ionorRest
ri
cti
onoper
ati
on:Thesel
ect
ionoper
ati
oni
saunar
yoper
ati
on.
107
Thi
sisusedt
ofi
ndhor
izont
alsubsetofr
elat
ionort
upl
esofr
elat
ion.I
tisdenot
edby
si
gma(σ).
Ex.I
fyou wantal
lthe empl
oyees hav
ing sal
arymor
ethan 9,
000 f
rom r
elat
ion
Empl
oyee.Thequer
y,sσ
i sal
ary>9,
000(Empl
oyee) Ther
esul
tisshowni
nFi
gur
e.
EI
D Name Sal
ary
1E John 10,000
5E Nil
e 15,000
Fi
g.Resul
tofsel
ect
ionoper
ation.
Wecanal
socombi
net
heseoper
ati
ons.I
fyouwantnameofal
lempl
oyeeshav
ingsal
ary
l
essthan7,000.Thent
hequer sσ
yi sal
ary<7, πName(Empl
000[ oyee)]
St
ep1.Fi rstweappl
yproject
ionoper at
iononrelat
ionemploy
eetogetnameofal
l
employees.
πName(Empl
oyee)
St
ep2.Thenweappl
ysel
ect
ionoper
ati
ont
ochooseempl
oyeeshav
ingsal
aryl
ess
t
han7,
000.
σsalary<7,
[ πName (
000( Empl
oyee)
)]→ Rel
ati
onalal
gebr
aexpr
essi
on.The
r
esul
tis.
Name
Ramesh
Jack
Resul
tofσsalary<7,000[
πname(Empl
oyee)
].
b)Pr
( oject
ionoperati
on:Theproj
ecti
onoper ati
onisaunaryoper
ationwhi
chappl ies
onlyonasinglerel
ati
onatatime.Proj
ectoperat
ioni
susedtoselectv
ert
icalsubset
ofrelat
i i
on(.
e.,
columnsoftabl
e).I
tisdenotedbypi(
π).
Consi
derFi
gur
e5.
1.I
fyouwantal
lthenamesofempl
oyeesandt
hei
rsal
aryf
rom
r
elat
ionempl
oyee.Thenquer
y,sπ
i name,
sal
ary(Empl
oyee) Ther
esul
tis
Name Salary
John 10,000
Ramesh 5,
000
Smith 8,
000
Jack 6,
000
Nil
e 15,000
(c)Divi
sionoperati
on:Divisi
onoper
ati
oni
susefuli
nspeci
alki
ndofquer
iest
hatinclude
thephrase“f
orall”.I
tisdenot
edby(÷)
.Iti
sli
kethei
nver
seofCart
esi
anproduct.For
exampl
e:
X Y
108
X1 Y1 A B1 B2 B3
X1 Y3 Y Y Y
X1 Y2 Y1 Y1 Y5
X4 Y Y3 Y5 Y2
X5 Y5 Y4
X2 Y3
X3 Y4
X4 Y1
A÷B1gi
ves A÷B2gi
ves A÷B3gi
ves
X X X
X1 X1 X5
X4 X4
X1
X2 X5
X3
Fi
g.Resul
tofdi
vi
sionoper
ati
on.
LetRbet
her
elat
ionwi
thschemarandSbet
her
elat
ionwi
thschemas.LetS⊆R.Then
eti
Tupl sinr÷si
fandonl
yif
(
i) ti
sinπR–S(
r)
(
i)I
i ft
upl
eispr
esenti
ntheCar
tesi
anpr
oductofSandR.
(d)Natur al
-joi
noperati
on:Nat uralj
oini
susedt ojoint
worelat
ionshavinganynumber
ofat tri
butes.I
tisdenotedbysy mbol( ).Italsoopt
imizethequeryasCar tesi
an
productgi vesunnecessaryresul
tsandset-
unionandset-
int
ersect
ionoperat
ionsare
applicableonlyont hoserelati
onsthathav
eequalnumberofat t
ri
buteswithsame
data-type.
Considert hefoll
owingrelat
ions
Employ ee Department
EI
D Name Salar
y Dept
-ID Dept
_ID Dept_
Nam
1 Amit 5,000 10 e
2 Sachi
n 8,000 20 10 Sal
es
3 Vi
nay 2,000 20
20 Pur
chase
4 Vi
vek 6,000 10
Ex.Fi
ndt
henamesofal
lempl
oyeesf
rom r
elat
ionempl
oyeewi
tht
hei
rrespect
ive
depar
tmentnames.Thequer
yis
Empl
oyee Depar
tment
109
πName,Dept
_name Empl
oyee⋅
EID =Depar
tment
⋅Dept
_ID Ther
esul
tis
Name Dept-Name
Amit Sal
es
Sachi
n Purchase
Vi
nay Purchase
Vi
vek Sal
e
e)Out
( erj
oin:OuterJoi
ni sanextensi
onofnaturalj
oinoper
ati
ons.I
tdeal
swi
tht
he
missi
nginfor
mationcausedbynatur
alj
oinoper
ati
on.
Supposey
ouneedal
li
nfor
mat
ionofal
lempl
oyeesandal
lst
udent
sinasi
ngl
erel
ati
on.
Nat
uralj
oin( ):Thenat
uralj
oin(
Empl
oyee St
udent
)gi
vest
her
esul
tasshown
bel
ow
EI
D SI
D Name Salary Fees
1E 5S John 10,000 1,
000
3E 1S Smith 8,
000 1,
000
5E 4S Nil
e 15,000 1,
500
I
nthi
sresul
t,i
nformati
onaboutRamesh,Jack,Vi
jay,Gauravar
emissing.So,out
erj
oin
i
susedtoavoi
dt hi
slossofi
nfor
mati
on.Therearethreety
pesofouterjoi
ns.
(
i) Lef
tout
erj
oin:I
tisusedt
otakeal
ltupl
esofr
elat
iont
hatar
eont
hel
eftsi
de
whet
hert
heyar
emat
chi
ngwi
tht
upl
esofr
ightsi
der
elat
ionornot
.Iti
sdenot
edby
(
⟕.).
(
Empl
oyee⟕ St
udent
)gi
ves
EI
D SID Name Salary Fees
1E 5S John 10,000 950
2E NULL Ramesh 5,
000 NULL
3E 1S Smit
h 8,
000 1,000
4E NULL Jack 6,
000 NULL
5E 4S Nil
e 15,000 1,500
Empl
oyeerelat
ioni
satl ef
tsidesot abl
eint heaboveconsist
salli
nfor
mat
ionof
Empl
oyeer
elati
onbutst
il
lmissi
ngi
nfor
mationaboutVi
jayandGaurav
.
(
i) Ri
i ghtout
erj
oin:I
tisusedt
otakeal
ltupl
esofr
elat
iont
hatar
eont
her
ightsi
de
whethert
heyar
emat
chi
ngwi
tht
upl
esofl
eftsi
der
elat
ionornot
.Iti
sdenot
edby
(
⟖. )
.
(
Empl
oyee⟖.
Student
)gi
ves
EI
D SI
D Name Salary Fees
3E 1S Smith 8,
000 1,000
NULL 2S Vij
ay NULL 950
NULL 3S Gaur
av NULL 2,000
5E 4S Nil
e 15,000 1,500
1E 5S John 10,000 950
110
Studentr
elat
ionisatrightsi
desotabl
eint
heaboveconsi
stsal
li
nfor
mat
ionofSt
udent
r
elat
ionbutsti
ll
mi ssi
nginfor
mati
onaboutRameshandJack.
(
ii
i) Ful
lout
erj
oin:I
tisusedt
otakeal
ltupl
esf
rom l
eftandr
ightr
elat
ionwhet
hert
hey
match wit
h each ot
herordi
d notmat
ch.I
tis denot
ed by(
⟗.)
.(Empl
oyee
⟗.Student
)gives
EI
D SI
D Name Sal
ary Fees
1E 5S John 10,000 950
2E NULL Ramesh 5,
000 NULL
3E 1S Smith 8,
000 1,000
4E NULL Jack 6,
000 NULL
5E 4S Nil
e 15,000 1,500
NULL 2S Vij
ay NULL 1,000
NULL 3S Gaurav NULL 2,000
Tabl
eabov
econsi
stal
linf
ormat
ionofEmpl
oyeeandSt
udentr
elat
ion.Her
e,noi
nfor
mat
ion
i
smissi
ng.
Poi
ntst
oRemember
- Per
for
m pr
oject
ionandr
est
ri
cti
onassoonaspossi
ble.
- Conv
ertt
woormor
eoper
ati
onsi
ntosi
ngl
eoper
ati
oni
fpossi
ble.
- Whi
l
ejoi
ningt
wot
abl
esputsmal
ltabl
eonRHS.
- Atrunt
ime,
youwi
l
lseeabl
ankspacei
nst
eadofNULL.Forbet
terunder
standi
nguse
“NULL”
.
Exampl e.Gi
ventworel
ati
onsR1andR2, whereR1contai
nsN1t uples,
R2containsN2
tupl
esandN2>N1>0.Det ermi
nethemaxi mum andmi nimum numberoft uples
produced byeach ofthe f
ollowi
ng r
elati
onalalgebr
a expressions.Also st
ate any
assumpt i
onaboutR1andR2formakingtheexpressi
onmeaningf ul.
a)R1
( R2
b)R1 R2
(
c)R1–R2
(
d)R1×R2
(
e)σ
( a=10(R1)
(
f)πb(R2)
Sol.Thefoll
owi
ng tabl
egivestheassumpt i
onsand corr
espondi
ng mi
nimum and
maximum t
upl
esproducedbyeachr
elat
ional
algebr
aexpr
essi
on.
Expr
essi
on Assumpt
ion Mi
n. Max.
a) R1 R2
( R1andR2ar
eUni
onCompat
ibl
e N2 N1+N2
b) R1
( R2 R1andR2ar
eUni
onCompat
ibl
e 0 N1
c) R1–R2
( R1andR2ar
eUni
onCompat
ibl
e 0 N1
111
d) R1×R2
( N1*N2 N1*N2
e) σa=10(
( R1) R1hasanat
tr
ibut
enameda 0 N1
f
() πb(
R2) R2hasat
tri
but
eb,
N2>0 1 N2
6.
2.1.
3Ext
endedRel
ati
onal
-Al
gebr
aOper
ati
ons
Inaddit
iontothefundament
aloperat
ions,t
her
ear
esomeaddi
ti
onaloper
ati
onst
o
makerel
ati
onal
algebr
amorefl
exi
ble.
Ext
endedRel
ati
onal
-Al
gebr
a-Oper
ati
ons
(
a)Generali
zedProj
ecti
on:Ext
endstheproj
ect
ionoper
ati
onbyal
l
owi
ngar
it
hmet
ic
funct
ionstobeusedi
ntheproj
ect
ionl
i
st.
F1,
F2,
…, (E)
Fn
Ei
sanyr
elat
ional
-al
gebr
aexpr
essi
on
EachofF1,F2,…,Fn ar
ear
it
hmet
icexpr
essi
onsi
nvol
vi
ngconst
ant
sandat
tr
ibut
esi
nthe
schemaofE.
(
b) Aggr
egat
eFunct
ionsandOper
ati
ons
Aggregate orsetf unct
ions ar ei nt
roduced tor el
ati
onalalgebr at oincrease it
s
expressiv
epower .Anaggr egatef uncti
onoperatesonasetofv alues(tuples)and
comput esonesingleval
ueasout put.Thesefuncti
onstakeacol lect
ionofv aluesand
ret
urnasi ngl
evalueasaresult.Theaggr egat
eoperati
oninrel
ationalalgebr
ai sdefi
ned
as
G1,
G2,
…,Gn F1(A1)
,F2(A2)
,…, E)
(
Fn(An)
Ei
sanyr
elat
ional
-al
gebr
aexpr
essi
on
G1,
G2…,
Gni
sal
i
stofat
tri
but
esonwhi
cht
ogr
oup(
canbeempt
y)
EachFii
sanaggr
egat
efunct
ion
EachAii
sanat
tri
but
ename
denot
est
hechar
act
erscr
ipt
-F
Thev
ari
ousaggr
egat
efunct
ionsar
e
a)Av
( g(av
eragev
alue):
comput
est
heav
erageofal
lval
uesi
nthe(
numer
ic)set
b)Mi
( n(mi
nimum v
alue)
:fi
ndst
hemi
nimum v
alueofal
lval
uesi
ntheset
c)Ma
( x(
maxi
mum v
alue)
:fi
ndst
hemaxi
mum v
alueofal
lval
uesi
ntheset
d)Su
( m(
sum ofv
alues)
:comput
est
hesum ofal
lval
uesi
nthe(
numer
ic)set
e)Co
( unt(
numberofv
alues)
:ret
urnst
hecar
dinal
i
ty(
numberofel
ement
s)i
ntheset
Theresul
tofaggr
egat
iondoesnothav
eaname.Youcanuser
enameoper
ati
ont
ogi
vei
t
aname.
Exampl
e.Consi
dert
her
elat
ionrasshownbel
ow:
112
1. sum(
c) r
( i
)=80(.
e.,
sum(
C)=80)
2. max
(c) r
( i
)=30(.
e.,
max(
C)=30)
3. mi
n(c)r
( i
)=13(.
e.,
sum(
C)=13)
4. count
(c) r
( i
)=4(.
e.,
sum(
C)=05)
5. av
g(c)r
( i
)=20(.
e.,
sum(
C)=20)
6.A sum(
c) r
()gi
vest
hef
oll
owi
ngt
abl
e:
A C
a 37
b 43
7.A sum(
c),
count
(* r
)()gi
vest
hef
oll
owi
ngt
abl
e:
A C count
a 17 2
b 63 2
8.B sum(
c),
count
(* r
)()gi
vest
hef
oll
owi
ngt
abl
e:
B C count
a 37 1
b 43 3
(
c) Renameoper
aton:
i
Ther enameoper ati
onisaunar yoperati
onwhi chi
susedt ogi
venamestor el
ati
onal
algebraexpressions.Itisdenot edbyr ho(ρ).Suppose,y
ouwantt ofi
ndCar t
esian
productofar elati
onwi t
hitsel
fthenbyusingrenameoperat
orwegiv
eanaliasnamet o
thatrelat
ion.Now,y oucaneasi l
ymul t
ipl
ythatrel
ati
onwithit
sali
as.Iti
shelpfulin
remov i
ngambi guit
y.It
sgeneralf or
misρx (R)wher eRbeanyr el
atonandxbet
i he
ali
asnamegi ventor el
ati
onR.
Ex.Fi
ndt
hehi
ghestsal
aryi
nEmpl
oyeer
elat
ion.
Todothi
s,f
ir
stmakeatempor
aryrel
ati
onthatcont
ainsal
lsalari
esexcepthi
ghestone.
Thent
akethedif
fer
enceoft
emporar
yrel
ati
onwi t
hemployeerelat
ion.
Quer
yisπsalary(
Empl
oyee):
πempl
oyee.
sal
ar σempl
y[ oyee.sal
ary<a.sal
ary(
Empl
oyee×ρa(
Empl
oyee)
)]
Step 1.Take al
ias name ofrel
ati
on Empl
oyee byusi
ng r
ename oper
atorρa
(Employee).Her
eali
asnamei sa
113
Step2.TakeCar
tesi
anpr
oductofr
elat
ionEmpl
oyeewi
thi
tsal
i
as.Thi
sgi
vesal
l
combi
nat
ions.
[
Empl
oyee×ρa(Empl
oyee)
]
Step3.Now,chooset
hesal
aryi
nawayt
hatt
empor
aryr
elat
ioncont
ainsal
lsal
ari
es
excepthi
ghestone.
πempl
oyee.
sal
ar σempl
y[ oyee.sal
ary<a.sal
ary(
Empl
oyee×ρa(
Empl
oyee)
)]
St
ep4.Takeset
-di
ff
erenceoft
empor
aryr
elat
ionwi
thr
elat
ionempl
oyee.Ther
esul
tis
Sal
ary
15,
000
Thesecondf
orm ofr
enameoper
ator
:Youcanal
sor
enamet
heat
tr
ibut
esofany
rel
ati
on.
ρx(A1,A2,…,An)(E)
whereA1,A2,
…,Anarenewnamesf oratt
ri
butesofrel
ati
onE.
ρ
Considert
herelati
onstudent Student
s( St
udent_
ID,St_
Name,St_Fees)(St
udent)
.The
resul
tis
Student
St
udent
_ID St
_Name St
_Fees
1S Smith 1,000
2S Vij
ay 950
3S Gaurav 2,000
4S Nil
e 1,500
5S John 950
Fi
g.Resul
tofr
enameoperat
iononstudentr
elat
ion.
(d)Assignmentoper
aton:Assi
i gnmentoper
ationisusedtoassi
gnt empor
arynames
t
orelat
ionalal
gebr
aexpr
essi
ons.I
tisusef
uli
nlargeexpr
essi
ons.I
tisdenot
edby(←).
Consi
deranexpr
essi
on.
πID,Name[σdept=“Sal
es”(Empl
oyee)
]temp1← σdept=“
Sal
es”
(Empl
oyee)
Now,
youcanwr
it
eabov
eexpr onasπ
essi I
D,Name(
temp1)
6.3 Rel ati
onalcalculus
Anal t
ernativetorelati
onalalgebraisr el
ationalcalculus.Itisaquer ysy stem where
queri
esar eexpressed asv ari
ablesand f or mulason t hesev ar
iables.Iti sa non-
proceduralordeclar
at i
vebynat ur
e.Inthis,thef ormulasdescribethepr operti
esofthe
requi
redr esul
trel
ati
onwi thoutdescri
binghowt ocomput eiti.
e.,quer yrepresent
sonly
resul
tsandhi desthepr oceduret ofi
ndt her esult
.Rel at
ionalcal culusisbasedon
114
predicatecalcul
us,whi chi susedt o sy
mbolizelogi
calargumentsinmat hemat i
cs.
Relationalcal
cul
ushast wov ar
iant
s.Thefi
rstoneiscal
ledTupleRel
ati
onalCalcul
usin
whichv ar
iabl
estakeont upl
esasv al
ues.Thesecondonei scaledDomai
l nRel at
ional
Calculusinwhichv ar
iabl
esr angeovert
heunderly
ingdomains.
Relat
ionalCal
cul
ushasst
rongl
yinf
luencedt
hedesi
gnofmanyquer
ylanguagesl
i
keSQL
andQBE.
6.
3.1Tupl
eRel
ati
onalCal
cul
us
Everyquer
yintupl
erel
ationalcal
cul
usisexpressedbyatuplecalcul
usexpr
essi
on,
whichi
sthebasi
cconst
ruct.Atupl
ecal
cul
usexpressi
oni
softhefor
m
Her
e,Tisasetoftupl
ev ar
iabl
eandFisthef
ormul
ainvol
vi
ngT.Ther
esul
toft
hisquer
y
i
sthesetofal
lt estf
upl orwhicht
hefor
mulaF(T)i
str
uewithT=t.
At upl
ecalcul
usexpressi
onisanon-
procedur
aldef
ini
ti
onofsomer
elat
ioni
nter
msof
somegivensetofr
elati
ons.
6.
3.1.
1Basi
cConcept
s
Here,wediscussabouthowthetuplecal
cul
usf
ormul
ascanbeder
ivedandt
hev
ari
ous
concept
srelat
edwiththesef
ormulas.
1.Fr
eevar
iabl
es:Eacht
upl
evar
iabl
ewi
thi
naf
ormul
aisei
therf
reeorbound.Av
ari
abl
e
wit
hinaformulaissaidtobef
reei
fiti
snotquant
if
iedbyt
heexi
stent
ialquant
if
ier(
∃)
ortheuni
versalquant
ifi
er(
∀).
2.Boundvar
iabl
es:Avar
iabl
einaf
ormul
aissai
dtobeboundi
fiti
squant
if
iedbyei
ther
exi
stent
ial
quant
if
ier(
∃)ort
heuni
ver
sal
quant
if
ier(
∀).
3.Qual
if
iedvar
iabl
e:Aqual
i
fiedv
ari
abl
eisoft
hef
ormt
(A) eti
,wher sat
upl
evar
iabl
e
ofsomer el
ati
onandAisanattr
ibut
eofthatr
elat
ion.Twoqual
i
fiedv
ariablesP(
A)
andQ(B)aredomai
ncompat
ibl
eifatt
ri
but
esAandBar edomai
ncompatible.
4.At
om orat
omi
cfor
mul
a:Anat
om orat
omi
cfor
mul
amaybei
nanyoft
hef
oll
owi
ng
f
orms:
(
i) t∈R, eti
wher satupl
evari
ableandRisar el
ati
on.
(
i)t
i A]⊗ p[
[ B]
,where⊗ isanyoneofcompar isonoper
at s(=,≠,<,>,≤,≥)andt
or [A]
andp[B]ar
edomai ncompatibl
evari
ables.
(
ii
i)t[
A]⊗Const ant⊗ t
antorConst [
A],whereconst
antmustbedomaincompat i
ble.
5.We l
lfor
medFor mula(WFF):Awel lformedformula(WFF)isr
ecursi
velydefi
nedt o
beoneoft
hef
oll
owi
ng:
(
i) Ev
eryat
om i
saWFF.
(
i)I
i ffi
saWFF,
thensoar
e(f
)and¬f
.
(
ii
i ffandgar
)I eWFF’
s,t ef∨g,
hensoar f∧g,
f→ g.
115
(
iv ff
)I x)i
( saWFFandxi
sfr
ee,
then∃x(
f(x)
)and∀x(
f(x)
)ar
eal
soWFF’
s
6.Cl
osedWFF:AWFFi
ssai
dtobecl
osedi
fitdoesnotcont
ainanyf
reev
ari
abl
e.
7.OpenWFF:AWFFi
ssai
dtobeopeni
fitcont
ainsatl
eastonef
reev
ari
abl
e.
Consi
dert
her
elat
ionEmpl
oyeeandDepar
tmentasf
oll
owsf
orexampl
esont
upl
erel
ati
onal
cal
cul
us.
Empl
oyee Depar
tment
EI
D Name Sal
ary Dept
-I
D Dept
-I
D Dept
-Name
1 Anand 7,
000 1 1 Sal
es
2 Sumit 8,
000 2 2 Marketi
ng
3 John 5,
000 1 3 Accounts
4 Rahul 6,
500 2
5 Pankaj 9,
000 3
Fi
g.Rel
ati
onempl
oyeeanddepar
tment
.
Exampl
es
1.Fi
ndall
empl
oyee,
hav
ingsal
arymor
ethan7,
000
t
{|t
∈empl
oyee ∧ t[
Sal
ary
]>7000}
↓ ↓
t∈r t[A]
↓
t
{|
P(t)
}
I
tmeanswefi
ndt hosetupl
e(t
)thatbel
ongt
orel
ati r
on()Empl
oyeeandhav
ingsal
ary
moret
han7,
000.Theresulti
s
EI
D Name Sal
ary Dept
-I
D
2 Sumit 8,
000 2
5 Pankaj 9,
000 3
2.Nameofemploy
eeshav
ingsal
arymor
ethan7000.
Her
eweusenot
aton ∃t∈r
i [ t
P()]
I
tmeanst
her
eexi
stat ett
upl hatbel
ongt
orel
atonrsucht
i hatpr
edi
cat t
eP()i
str
ue.
{t
|∃t∈Empl
oyee(s[
Sal
ar]=t[
y Sal
ar]∧t[
y Sal
ary
]>7, }
000)
↓
Projecti
on
tmeansti
I satupl
einrel
ati
onemployeef orwhichval
ueoftuplesandtareequalfor
at
tri
but
esal
aryandf
ort etv
upl al
ueofatt
ri
but esal
aryi
sgreat
erthan7000.Ther
esultis
Name
Sumit
Pankaj
116
3.Nameanddepar
tmentofempl
oyeesthatareworki
ngi
nmar ket
ingdepar
tment
.
t∃t
| ∈Empl oyee( name]=t[
s[ name]
∧∃U∈Department(U[Dept- =t[
Name] Dept-
Name]
∧U[
Dept
-Name]=“
Mar
ket
ing”
))
Firstl
i
neofquer
ygivest
henameat t
ri
butef
rom r
elat
ionemploy
eeoriti
sli
kepr oj
ect
ion
then∧operat
oract
sasjoi
noperat
ionofrel
ati
onEmployeeandDepar
tment.Lastl
ineof
queryact
sassel
ecti
onoper
ati
on.Theresul
tis
Name Dept
-Name
Sumi
t Mar
ket
ing
Rahul Mar
ket
ing
4.Namesofempl
oyeesot
hert
hanJohn.
t
|¬∃t
∈Empl
oyee( name]=t[
s[ name]
∧t[name]="John"
)
Ther
esul
tis
Name
Anand
Sumit
Rahul
Pankaj
6.
3.2Domai nRelat
ionalCal
culus
Everyqueryi
nDomai nrel
ati
onalcal
culusi
sexpr
essedbyadomaincal
culusexpr
essi
on,
whichisthebasi
cconstruct
.Adomai ncal
cul
usexpressi
oni
soft
heform
[
D|F(
D)]or{
(d1,
d2,
.
..
,dn)
|F(
(d1,
d2,
.
..
,dn)
)}
Her e,Disasetofdomai nv ar
iabl
es(d1,d2,
..
.dn)andFi
, safor
mulainvolvi
ngD(d1,d2,.
..
,
dn)
.Ther esultofthi
squer yisthesetofal ltupl
esf orwhi
chtheformul aistr
ue.The
operatorsusedbyt heDomai nrelat
ionalcalcul
usar esameast hoseusedbyt upl
e
rel
ationalcalcul
us.At uplerel
ati
onalcalcul
usexpr essi
oncanbeconvertedtoadomai n
calculusexpressionbyr epl
acingeacht upl
ev ari
ablebyndomainvariabl eni
es,wher s
thear i
tyofthetuplevari
able.
6.
3.2.
1 Basi
cConcept
s
Thedefi
nit
ionsofFreevariabl
es,Boundvari
abl
esandQuali
fiedv ar
iabl
esaresameas
i
ntupl
erel
at i
onalcal
cul
us.Here,wediscussaboutot
herdef
init
ionsthatar
edif
fer
ent
f
rom t
upl
er el
ati
onalcal
culus.
Atom orAt
omi
cfor
mul
a:Anat
om orat
omi
cfor
mul
amaybei
nanyoft
hef
oll
owi
ng
f
orms:
(
i) D∈R, wher d1,d2,.
eD( ..
,dn)i
sthesetofdomai
nvar
iabl
esandRi
sar
elat
ionwi
thn
at
tr
ibut
es.
117
(
i) X⊗Y,
i wher
e⊗i
sanyoneofcompar
isonoper
ator
s(=,
≠,<,
>,≤,
≥)andXandYar
e
domai
nvar
iabl
es.
(
ii
i) X⊗Const
antorConst
ant⊗X,
wher
econst
antmustbedomai
ncompat
ibl
e.
Wellformedfor
mula(WFF):Awel
lfor
medf
ormul
a(WFF)i
srecur
siv
elydef
inedt
obe
oneofthefol
l
owing:
(
i) Ev
eryat
om i
saWFF.
(
i)I
i ffi
saWFF,
soar
e(f
)and¬f
.
(
ii
i ffandgar
)I eWFF’
s,t ef∨g,
hensoar f∧g,
f→ g.
(
iv ff
)I x)i
( saWFFandXi
sfr
eeandadomai
nvar
iabl
e,t f
hen∃X((x) f
)and∀X((x)
)ar
eal
so
WFF’
s.
Themajordi
ffer
encebetweentupl
erel
ationalcal
cul
usanddomainrel
ati
onalcal
culusis
thati
ndomaincalcul
usthedomainvar
iablesareusedt
orepr
esentcomponentoftuples
i
nsteadoft
uplesvari
abl
esusedintupl
ecal cul
us.
Agai
ntherel
ati
onEmpl
oyeeandDepar
tmentar
eusedf
orexampl
esondomai
nrel
ati
onal
cal
cul
us.
EI
D Name Sal
ary Dept
-I
D Employee Dept
-I
D Dept
-Name
1 Anand 7,
000 1 1 Sal
es
2 Sumit 8,
000 2 2 Marketi
ng
3 John 5,
000 1 3 Accounts
4 Rahul 6,
500 2 Depart
ment
5 Pankaj 9,
000 3
Exampl
es
1.Fi
ndal
lempl
oyeeshav
ingsal
arymor
ethan7000.
{
<E,
N,S,
D>|
<E,
N,S,
D>∈Empl
oyee∧S>7000}
2.Nameofempl
oyeeshav
ingsal
arymor
ethan7000.
{
<N>|
∃E,
S,D(<E,
N,S,
D>∈Empl
oyee∧S>7000)
}
3.Nameofempl
oyeesot
hert
hanJohn.
{
<N>|
∃E,
S,D(
<E,
N,S,
D>∈Empl
oyee∧N≠“
John”
)}
4.NameandDepar
tmentofempl
oyeeswhoar
ewor
kingi
nmar
ket
ing
depar
tment
.
{
<N,
DN>|
∃E,
S,D(
(<E,
N,S,
D>∈Empl
oyee∧∀<DI
D>∈Depar
tment
)
118
∧(
D=DI
D∧DN=“
Mar
ket
ing”
))}
6.
4 Compar
isonofdomai
nrel
ati
onal
cal
cul
usandt
upl
erel
ati
onalcal
cul
us
S.
No Domai
nRel
ati
onalCal
cul
us Tupl
eRel
ati
onalCal
cul
us
.
1. I
ndomainrel
ati
onalcal
cul
us,the I
ntupl
erel
ati
onal
calcul
us,
the
v
ari
abl
esrangeoverfi
eldv
alues. v
ari
abl
estakeontupl
esasval
ues.
2. I
tst
rongl
yinf
luencesSQL. I
tst
rongl
yinf
luencest
heQBE.
3. Indomai nrel
ati
onalcalcul
us, I
nt upl
erel
ati
onal calculus,i
tispossibl
e
addi
tionalrul
esareneededt odeal
wit
h t
or est
ri
ctanyexistentiall
yquali
fied
thesafetyofexpressi
ons. v
ariabl
etorangeov eraspecific
r
elati
onforsafeexpr essions.
4. I
tisanon-
procedur
all
anguage. I
tisal
soanon-
procedur
all
anguage.
6.
5 Compar
isonofRel
ati
onal
cal
cul
usand Rel
ati
onalal
gebr
a
S.
No Rel
ati
onalCal
cul
us Rel
ati
onal
Algebr
a
.
1. I
tisnon-pr
ocedur
alordecl
arat
ive I
tisapr
ocedur
all
anguage.
l
anguage.
2. I
thasabi
ginf
luenceonquer
ylanguages I
thasbiginf
luenceonalmostall
quer
y
l
i
keSQLandQBE. l
anguagesbasedonrelat
ions.
3. Itdescr
ibesthesetofanswerswithout Therelat
ional
algebraquerydescr
ibesa
beingimpli
citabouthowtheyshouldbe stepbystepprocedureforcomputing
comput ed. thedesir
edresult
.
4. Allr
elati
onalalgebraqueri
escanbe Iti
srestr
ict
edt
osaf
equer
iesont
he
expressedinrelat
ionalcal
cul
us. cal
culus.
5. Therel
ati
onalcal
culusexpr
essioncan Acert
ainorderamongtheoper
ations
bewrit
teni
nanyor derandtheorder i
simpli
cit
lyspeci
fi
edandtheorder
doesnotaff
ectthestrat
egyfor i
nfl
uencesthestr
ategyf
oreval
uating
119
ev
aluat
ingt
hequer
y. t
hequer
y.
6. Therel
ati
onal
cal
cul
usl
anguagesar
e Therel
ati
onal
algebr
aismor
euser
ter
se. fr
iendl
y.
REVI
EW QUESTI
ONS
120
____
_ _
A.At tri
butes C.t uples
B.Keyat tr
ibut es D.for eignkey s
7.Ther esultofR( A1,A2,…,An)XS( B1,B2,…,Bm )i sar elati
onwi t
h_ __
__
att
ri
but es.
A. n+m C.n–m
B.n*m D.m –n
8.IfRhasxt uplesandShasyt uples, thenRXSwi llhav
e_ __
__ _tupl
es.
A. x+y C.x*y
B. x–y D.y–x
9.____
_ _Oper ationall
owsust opr ocessr el
ationshi
psamongr elat
ions.
A. pr oj
ect C.minus
B.Joi n D.uni on
10.
Thej oinoper ationwherewekeepal lthetuplesi
nr el
ati
onR,oral lthoseinrel
ati
onS,
orallthosei nbot hrel
ati
onsr egar dlessofwhet herornottheyhav emat chi
ngtupl
esis
cal
led_ _join.
A. out er C.External
B.Inner D.rel
at ed
CHAPTERSEVEN
STRUCTUREDQUERYLANGUAGE
7.1.Str
uct uredQuer yLanguage
Struct
uredQuer yLanguage, commonl yabbr eviat
edt oSQLandpr onouncedas“ sequel
”,
i
snotaconv entionalcomput erpr ogrammi ngl anguagei nthenormalsenseoft he
phrase.Ital l
owsuser st oaccessdat ainr el
ationaldatabasemanagementsy st
ems.
SQLi saboutdat aandr esults,eachSQLst atementr eturnsar esul
t,whethert
hatresult
beaquer y,anupdat et oar ecor dort hecr eat i
onofadat abaset abl
e.SQLi smostof t
en
usedt oaddr essar elationaldat abase,whi chi swhatsomepeopl erefertoasaSQL
database.Soi nbr i
efwecandescr ibeSQLasf oll
ows:
•SQL
- st andsf orSt ructur edQuer yLanguage
- Al lowsuser st ocr eateanddr opdat abasesandt ables.
- allowsy out oaccessadat abase
- canexecut equer iesagai nstadat abase
- canr etrievedat af rom adat abase
- cani nser tnewr ecor dsi nadat abase
- candel eter ecor dsf rom adat abase
- canupdat er ecor dsi nadat abase
- Al lowsuser st ocr eatev i
ew, storedpr ocedur e,
functionsinadatabase.
- Al lowsuser st osetper missionsont ables,proceduresandv i
ews
121
I
naddi
ti
on,
t hefol l
owingar ethecommonchar act
eri
sti
csofSQLCommands
- SQLkey wordsarenotnor mal
lycasesensi
ti
ve,
thatmeansitdoesnot
diff
er entiat
ethemeani ngoflowercaseanduppercaseincommand
execut ion
- New- linecharactersareignor
edinSQL,soacommandmaybeal lononel
i
ne
orbr okenupacr ossanumberofl i
nesfort
hesakeofclari
ty.
- ManyDBMSsy stemsexpecttohaveSQLcommandst erminatedwit
hasemi
-colonchar acter,buti
tisopti
onal
Char
act
eri
sti
csofSQL
- SQLi
sextr
emelyfl
exi
ble.
- SQLusesafr
eefor
m sy nt
axt
hatgi
vest
heusert
heabi
l
ityt
ost
ruct
ureSQL
st
atement
sinawaybestsui
ted.
-I
tisaf
reef
ormat
tedl
anguage,
i.
e.,
ther
eisnoneedt
ost
artSQLst
atement
sina
par
ti
cul
arcol
umnort
obef
ini
shedi
nasi
ngl
eli
ne.
-I
thasrel
ativ
elyfewcommands.
-I
tisanon-procedur
all
anguage
7.
2.SQLBasicDat aTy pes
Dat
atype Descr i
ption Size
Number(
p,s) I tisusedt ostorenumer icdatatypes.P Rangeofpisfr
om 1t
o38.
standsf orpreci
sion(totalnumberof Andsisfr
om –84to127.
deci maldigi
ts)andsst andsf orscal
e
(totalnumberofdi gi
tsaf t
erdecimal
point).
Dat
e Itisusedt ostoredateandt imev al
ues Rangeofdateisfrom Jan1,47
B.C.t
oDec.31, 9999A.D.
Char
(si
ze) I
tisusedt
ost
oref
ixedsi
zechar
act
er Rangeofcharis1
dat
a. (Bydefaul
t)t
o2000by tes.
Var
char
2(si
ze I
tisusedt
ost
orev
ar i
abl
esi
zechar
act
er Rangeofvarchar2is1
) dat
a. (Bydefaul
t)t
o4000by tes.
Long I
tisusedt
ost
orev
ari
abl
esi
zechar
act
er Rangeofl
ongi
supt
o2GB.
dat
a.
Cl
ob I
tisusedt
ost
orev
ari
abl
esi
zechar
act
er Rangeofcl
obi
supt
o4GB
dat
a.
122
Raw(
size) I
tisusedt
ost
oref
ixedbi
nar
ydat
a. Maximum si
zei
supt
o2000
by
tes.
Longr
aw I
tisusedt
ost
orev
ari
abl
ebi
nar
ydat
a. Maximum si
zei
supt
o2GB.
7.3.SQLCommands
Thesecommandsi ncludest andar dSQLcommandst ointeractwi thr elati
onal
databases.TheSQLcommandscanbecat egor i
zedi ntot hef ollowi ng4f unctional
groupsbasedont heirnat ure:
1.Dat aDef ini t
ionLanguage( DDL)st atement s:
Thesest atement sorcommandsar eusedt odef i
net hedat abasest ruct ureorschema.
Thecommoncommandsar e:
o Cr eat e-Cr eatesanewdat abase, at able, av i
ewofat able, orot herobj ecti n
database
o Al ter-modi f
iesthest ructureofanexi stingdat abaseobj ect ,suchasat able
o Dr op-del et esorr emov esanent iretable, av i
ewofat ableorot herobjecti nthe
databasesuchasf i
eldsandconst rai
nt s
o Tr uncat e-r emov eal lrecor dsf rom at able, i
ncludingal lspacesal l
ocatedf orthe
recordsar er emov ed
o Re name–r enameorchangenameofanobj ectofdat abase
2.Dat aMani pulationLanguage( DML)st atement s:
Thesest atement sorcommandsar eusedf ormanagi ngdat awi thinschemaobj ects.
Thecommoncommandsar e:
o SE LECT-r etr
iev edat afr om theadat abase
o I NSERT-i nser tdatai ntoat able
o UPDATE- updat esexi sti
ngdat awi t
hinat able
o DE LETE-del etesal lrecor dsf rom at able,thespacef ort her ecords
remai n
3.Dat aCont rolLanguage( DCL)st atement s.
Thesest atement sorcommandsar eusedt ocont roldat abaseobj ectsi nt er
msof
accesspr i
v i
leges.Thecommoncommandsar e:
o GRANT- givesuser '
saccesspr i
vilegest odat abase
o RE VOKE-wi t
hdr awaccesspr ivi
legesgi venwi tht heGRANTcommand
Thati sitt akesbackpr i
vilegesgr ant edf rom user
4.Tr ansact ionCont rol( TCL)st atement s:
Thesest atement sorcommandsar eusedt omanaget hechangesmadebyDML
statement s.I tallowsst atement stobegr oupedt oget herintol ogi caltransact i
ons.The
commoncommandsar e:
o COMMI T-sav ewor kdone
o SAVE POI NT-i dentifyapoi ntinat ransact iontowhi chy oucanl aterroll
back
o ROL LBACK-r est or
edat abaset oor iginalsincet hel astCOMMI T
123
SETTRANSACTION-Changet
ransacti
onopt
ionsli
kei
sol
ati
onlev
elandwhat
rol
l
backDMLstatement
scanberoll
backedwhereDDLareaut
ocommi t
.
7.
3.1.SQLDataDefi
nit
ionLanguage(DDL)
CreateCommand
- Creat
eDatabase:usedt
ocreat
eanewdat
abase.
Syntax:Creat
edat
abasedat
abase_
name;
Eg:Cr
eat
edat
abase
student_i
nfor
mati
on_
syst
em;
- UseDat
abase:usedt
ouseorassi
gny
ourowndat
abase
Synt
ax:
usedat
abase_
name;
Exampl
e:usest
udent
_inf
ormat
ion_
syst
em;
CREATI NGATABLE:
Tablesar ecreat edbyconsi deringt hefoll
owingthings:
- Name⇒ t henameoft het abletobecr eated
- Fi eld⇒ t henameoft hecol umnst obecr eated
- Dat atype⇒ t hedatat ypeoft hefiel
dtobecr eat
ed
- Lengt h⇒ Thesi zeoft hedat atype
- Const rai nt⇒ Rul esthatgov ernsthetable( i
tisopti
onal
)
Heret hefoll
owi ngchar actersar enotallowedt obeusedf orobj
ectnami
ng.
(+,
-,
/,>,<,
\,
!,
*,
%, $,#,(
,),.
,?whi tespaceet c)
Syntax:
CREATETABLEt abl
e_name(col
umn_name1data_t
ype(size),
column_
name2
data_t
ype(
size),col
umn_name3data_t
ype(
size)
,..
..
..
..
..
..
..
..
..
..
..
.col
umn_namen
data_t
ype(size)
);
Thedatatypespeci
fi
eswhatt y
peofdatathecol
umncanhol dandthesi
zespecifi
es
thel
engthofstr
ingsortexts.Youhavespeci
aldat
atypesfornumbers,
text,dat
es,et
c.
Examples:
- Number s:int,fl
oat,
numeric
- Text/St
ri
ngs:v archar(
X)–wher eXist
helengthofthest
ring
- Dates:dat
et i
me
Exampl
e:cr
eatetabl
estudent
(Sidvarchar(
10),
Lnamevarchar
(20)
,Fname
var
char
(20)
,Sexvar
char
(1),
Majorvar
char(10),
Credi
tsi
nt)
;
Inadditi
ont ot heabov e,thetablescanal sobecr eatedusingt hefol
lowi ngsy ntax
Syntax:
CREATETABLE<Tabl ename>
(col1dat atypeconst r
aint,col2datatypeconstraint,..
.col
ndat aty
peconst raint)
Constraintcanbepr imarykey ,notnull,
unique,foreignkey ,
etc.constraintsar eopti
onal.
Ifyouhav ey oucanusei tifnotyoucanl eavethespaceempt y.
Constrai
nt sar etherulesenf or
cedondat acolumnsont able.Thesear eusedt oli
mitthe
typeofdat at hatcangoi nt oatable.Thisensurest heaccuracyandr eliabil
ityofthedata
i
nt he database.Const raints could be column l evelort abl
el evel .Col umn level
constrai
nt sar eappli
edonl ytoonecol umn,wher eastablelevelconstraintsar eappli
ed
tothewhol etable.Foll
owi ngarecommonl yusedconst r
aintsavail
ableinSQL:
124
NOTNULLConst raint :Ensur est hatacol umncannothav eNULLv al
ue.
DEFAULTConst raint: Prov i
desadef aultv al
uef oracol umnwhennonei s
specifi
ed.
UNI QUEConst raint: Ensur est hatal lvaluesi nacol umnar edi ff
erent
.
PRI MARYKey :Uniquel yidentifiedeachr ows/ r
ecor dsinadat abaset abl
e.
FOREI GNKey :Uni quel yident ifi
edar ows/ recordsi nanyanot herdatabasetabl
e.
CHECKConst r
aint: TheCHECKconst raintensur esthatallvaluesinacolumn
sati
sfycertai
ncondi tions.
Hereisanexampl eofcr eat ingat ablewi thoutanyconst r
aint.
CREATETABLEst udent(i d_ nochar (12),F_namechar (20),Lnamechar (
20),Sexchar(
6),
E_yearint);
Theabov et abl
ewi llbesuccessf ull
yexecut ed.Butt het ablewi l
lnotbeav al
idtabl
ein
rel
ati
onaldat abasesy stem.I tv iolatest hepr imar ykeyconst rai
ntthusweneedt oadd
constrai
nts.Thedet ailsyntaxt ocr eateat ablewi thit
spr imarykeyi s.
Cr eati
ngaTabl ewi thPr imar yKeyConst raint
cr
eatetabl
eDepar
tment
(DIDchar(
5)pr
imarykey,
Namechar
(10)notnul
l
,Locchar
(10))
Theabovetabl
e(Depar
tment)wil
lconsi
derDIDasapr
imarykeyandNamecannott
ake
nul
landLochasnoconstr
aints.
Creat
ingaTablewithmorethanoneattri
but
easaPrimaryKey
creat
etableLoan(MIDchar
(3)notnul
l
,CIDchar(
3)notnul
l,BDat
edat
eti
menot
nul
l
,
DDatedateti
me,Const
rai
ntPk_LoanPr
imaryKey(MID,
CID,
BDate)
)
Theabov
etabl
e(Loan)wi
l
lconsi
derMI
D,CI
DandBDat
etoget
herasapr
imar
ykey
.
Cr eati
ngaTabl ewi t
hPr i
maryKeyandFor ei
gnKey
Primarykey( candidatekey)andforeignkeyattr
ibutesareusedtocreaterel
ationshi
p
betweentabl essot hatcrossref
erencingcanbeusedt oret
ri
eveint
errel
atedtuples
from t
het ables.
TheGener alsy ntaxwouldbe:
CREATETABLE<Tabl ename>
(att1dat aty
pePRI MARYKEY,at t2dat
atypeconstrai
nt,….
att
ndat aty
pe
constrai
nt,
FOREI GNKEY( Att
i)REFERENCES<homet able(
att
)>)
Thelastli
necanbechangedt othef oll
owingi
fwewantt oassignauserdef i
nednamefor
theconstraint
Const
rai
ntConst
Namef
orei
gnkey(
att
ri
but
e)r
efer
enceshomet
abl
e(at
tri
but
e)
Forexample:Assumingthatt
heDepart
mentandEmployeetablearerel
atedwit
heach
otherwheretheDepartmentI
d(DI
D)ispri
marykeyat
tri
but
epost edinEmployeetabl
e
asaf or
eignkeywit
ht henameEDID.Thecodi
ngmethodwil
l be.
cr
eat
etabl
eDepar
tment(DI
Dchar
(5)pr
imar
ykey,
Namechar
(10)notnul
l
,Loc
125
char(10))
creat
et abl
eEmpl oyee(EI Dchar(
5)pri
mar ykey,FNamechar (10)notnul l
,LName
char(10)notnul l
,Salarymoney,EDIDchar(5)foreignkeyr ef
erences
Depar tment(DID))
or
createt ableEmpl oyee(EI D char
(5)pri
mar ykey, FNamechar (10)notnul l
,LName
char(10) not nul l,Sal ar
y money,EDI D char (
5),f oreign key (EDI D) refer
ences
Depar t
ment ( DID))
OrtheaboveEmpl oyeetablecanbechangedt o
createt abl eEmpl oyee(EI Dchar(5)pri
mar ykey,FNamechar (
10)notnul l
,LName
char (
10)notnul l
,Salarymoney,EDI Dchar(5),ConstraintFk_Empf oreignkey(EDID)
referencesDepar tment(DID))
ALTERCOMMAND
o Alt
eringat abletochangedat adef i
nit
ionoft hetable
Onecanchanget hetabledefini
ti
onaf t
ercreati
ngt hetable.Thekindofchangemi
ght
be:
- Addinganewat tr
ibut et
oanexi sti
ngtable
- Deleti
ngandexistingattr
ibutefrom anexist
ingt abl
e
- Changingthedatat ypeandsi z
eofanexi sti
ngat tri
bute
- Addingmor econst r
aint
stoanexi sti
ngattri
buteofat ableli
kenotnull
.
cr
eatetabl
eEmployee(EIDchar
(5)pr
imar
ykey,
FNamechar
(10)notnul
l
,LName
char(
10)notnull
,Sal
arymoney)
AddCol umn/Att
ri
butetoanexi st
ingtabl
eSy ntax:
ALTERTABLE<t ablename>ADD<col umnname><dat atype><const
raint
>
- AddingDateOfBir
thinEmployeeTabl e
ALTERTABLEEmpl oyeeADDDoBDat et
ime
Aft
ert
hisinst
ruct
ionisexecut
ed,theempl oy
eet abl
ewill
havethefoll
owingschema.
EI
D FName LName Sal ar
y DoB
DROPCOMMAND
o Del eteaCol umn/ Attr
ibutefr
om anexi sti
ngt abl
eSy nt
ax:
ALTERTABLE<t ablename>DROP<col umnname>
o Del eti
ngDat eofBi rth(Dob)from Empl oyeeTabl e
ALTERTABLEEmpl oy eeDROPCOLUMNDoB
Ifanat t
ri
but e( acol umn)hav eaconst raint,wecannotdel eteisbyusi ngtheabov e
query
,insteadwehav et ofirstdrop/del
etet heconst raintont heatt
ribut
e( col
umn) .For
example,todel et eanat tr
ibutewhi chisaPr i
mar yKey ,fi
rstthepri
mar ykeyconst rai
nt
shoul
dbedr oppedbef or etryingtodeletethet able.
Inthenextt abl e,thepr imar ykeyar e(MI D,CID,BDate)wi t
hconst r
aintnamePk_ Loan.
Then,i
fwewantt odel etet heMI Dat t
ri
bute,wecannotsi mplydropitbeforeli
ft
ingt he
constr
aintoni t.Thusf irstthePk_ Loanshoul dbedel et edandt henMI Dcanbedel eted.
126
cr
eatetableLoan
(MIDchar(3)notnul
l
,CI Dchar
(3)notnul
l
,BDatedat
etimenotnul
l
,
DDatedateti
me,Constr
aintPk_
LoanPrimaryKey(
MID,CID,
BDat
e))
Thus:
Al
terTabl
eLoanDr
opConst
rai
ntPk_
Loan
Al
terTabl
eLoanDr
opCol
umnMI D
ChangeDef i
niti
onofaCol umn/ Att
ri
but
einaTabl eSyntax:
ALTERTABLE<t abl
ename>ALTERCOLUMN<col umnname><Newdat atype>
<NewSi ze><NewConst raint>
Eg:tochangethesi zeofNamei ntheDepar
tmentt ableabov efr
om 10t o
15char
ALTERTABLEEmpl oyeeALTERCOLUMNFNamechar (15)notnull
AddConst r
ainttoanexist
ingt abl
e
Afterat ableiscreat
edonecanaddconst r
aintsordel
eteconstraintstotheexi
sting
table.Const r
aintsmightbe:Pr i
maryKey,
ForeignKey,
Nul l
,Check, et
c.
Thegener alsyntaxwouldbe:
ALTERTABLE<t ablename>ADDCONSTRAI NT<const r
aintname><const r
aint>
a)AddPr imar yKeyConstrai
nt
Sy ntax:
ALTERTABLE<t
ablename>ADDCONSTRAI
NT<const
rai
ntname>Pr
imar
yKey
<(
att
ri
but
ename)>
E.
g.:ALTERTABLEEmployeeADDCONSTRAI
NTPK_
SupI
DPr
imar
yKey(
EID)
b)AddForeignKeyConst
rai
ntSy
ntax:
ALTERTABLE<tabl
ename>ADDCONSTRAI NT<const
rai
ntname>For
eignKey
<at
tri
but
ename>ref
erences<t
abl
ename><at
tr
ibut
ename>
Eg:ALTERTABLEEmployeeADDCONSTRAI
NTFK_
DIDFor
eignKey(
DID)
Refer
encesDepar
tment
(DI
D)
7.3.2.DATAMANI PULATI ONLANGUAGE( DML)
I NSERTCOMMAND
o Insertvaluesf oranExi st
ingtable
o I nserti
ngval uest oatablewithoutcodes
Toinser ti
ngv al
uest oat ablewi t
houtcodes, openthetableintheEnterpr
iseManager
andi nsertavaluei nthecol umnandmov etot henextusingTABkey .
- I nser t
ingvaluestoat ableusingcodesi nQuer yAnalyzer
Sy ntax:
INSERTI NTO<Tabl ename>VALUES( v al
uesseparatedbyacomma)
Inthei nserti
ntocommand, t
henumberofv aluesint
hecur vebracket‘
()’shouldmat
ch
witht henumberofat tr
ibutesoft hetar
gettabl e.I
naddit
ion,charact
erdatavalues
shoul dbeembr acedwithinsi ngl
equote‘ ‘
.
I
nser
ti
ngonet
upl
einEmpl
oyeet
abl
e
Eg:
INSERTI
NTOEmpl
oyeeVALUES(
'E01'
,
'chal
a'
,’
Tol
a’
,1250)
127
Formul t
ipl
etuplei
nserti
on,onehastorepeatedlyexecut
etheabov
ecodewithdi
ff
erent
values.
SELECTCOMMAND
Thiscommandi sf
orviewingthecont
entofat able.TheSELECTst
atementi
susedto
displayt
hecontentorpartofatabl
einat abl
ef orm.
Mostcommonl yusedpartsoftheSELECTstatementi st
hefoll
owi
ng:
SELECT<f
iel
dli
st>FROM <t
abl
es>WHERE<condi
ti
on>
GROUPBY<fiel
d>HAVING<aggregat
econdi
ti
on>
- Si
mpl
esel
ectst
atement
SELECT*FROM Empl
oyee
wher
etheast
eri
sk(*)meansal
ltheat
tri
but
esf
rom empl
oyeet
abl
e.
SELECTEI
D,FName,
Sal
aryFROM Empl
oyee
Cont
ainsonl
ythet
hreeat
tri
but
esf
rom empl
oyeet
abl
eint
her
esul
t.
SELECT*FROM Empl
oyeeWHERESal
ary>1000
Di
spl
ays,t
uplesf
rom theEmploy
eetabl
ewhosevaluef
ort
hesal
aryat
tr
ibut
eisgr
eat
er
t
han1000
- Todispl
ayatt
ribut
esfrom moret
hanonetabl
e
SELECT*FROM Employee,Depar
tmentWHERE
Empl
oyee.
EDI
D=Depart
ment .
DID
Thecondit
ionofselecti
onistheequali
tybetweenpri
marykeyandfor
eignkeyat
tr
ibut
es
fr
om thetworelat
edt abl
es.Buti
nsteadofusingthel
ongablenameinthecondi
ti
on,we
canrepr
esentthetablenamesbyav ar
iabl
ewhichi edal
scal
l ias.
ThustheaboveSQLcommandwi l
lbe:
SELECT*FROM Empl
oyeeE,
Depar
tment
D WHEREE.
EDI
D=D.DI
D
Or
,ifwewantt
osel
ectonl
ysomeoft
heat
tri
but
esf
rom t
het
wot
abl
es.
SELECTE.EID,E.
FName,E.Lname,D.NameFROM Empl oyeeE,Depar
tmentD
WHEREE. EDID=D.DID
I
nthesel
ectstat
ementinbui
l
taggregat
ef unct
ionsl
i
kecount(COUNT),maxi
mum
MAX)
( ,mini
mum ( MIN)
,aver
age(AVG),totalSUM)
( ,et
ccanbeused,wherei
nsuch
casest
hegroupbyphr
asewi
llbeused.
- Todispl
aysthemaxi
mum sal
aryfr
om eachdepar
tment
SELECTDI
D,MAX(
sal
ary)FROM Empl
oyeeGROUPBYEDI
D
- Todi
spl
ayst
heav
eragesal
aryf
rom eachdepar
tment
SELECTDI
D,AVG(
sal
ary)FROM Empl
oyeeGROUPBYEDI
D
- Tocountt
henumberofempl
oyeesi
neachdepar
tment
SELECTDI
D,MAX(
EID)FROM Empl
oyeeGROUPBYEDI
D
- Fort
henewat
tri
but
ecr
eat
ed,
wecangi
venewat
tr
ibut
enameusi
ngal
i
asmet
hod.
SELECTDID,
AVG( sal
ary)ASAvg_
Sal
aryFROM EmployeeGROUPBYEDID
Wecanal
sosor
ttheresul
tusingoneoft
heat
tri
but
esi
nt heresul
tusi heORDERBY
ngt
cl
ause.
SELECT*FROM Empl
oyeeWHERESal
ary>1000ORDERBYFName
128
DELETECOMMAND
Thisisf orDeleti
ngtupl esfrom at able.Todel etethewhol econt entofatuplefr
om an
existi
ngt ablewewilluset heDELETEcommand.
Gener alsyntax:
DELETE<TableName>WHERE<Condi t i
on>
- Todel eteandempl oyeewi t
hfirstname‘ Chal a’
DELETEempl oy eeWHEREFName=' Chal tu'
- Todel eteanempl oy eewi t
hempl oy eeid‘ e05’
DELETEempl oy eeWHEREEI D='e05'
Ifweuset hedelet
est atementwi thoutt hewher ecl ause(wi t
houtt hecondit
ion),
all
tuplesoft hetabl
ewillbedel etedandwewi l
l hav eanempt ytable.
DELETEempl oy ee
Theabov ecommandwi lldel
eteallthet uplesi nt heempl oyeet ablebutNOTt hetabl
e.
UPDATECOMMAND
Thiscommandi sformodi fy
ingat t
ributev aluesofat upl
e.Tomodi fyorupdate
attri
butev al
uesoftuplesi nanexi sti
ngt ablewewi llusetheUPDATEcommand.
Gener alsynax:
UPDATE<Tabl eName>SET<At rri
buteName=v alue>WHERE<Condi t
ion>
- Toi ncreasethesalar yofallemploy eesby5%
UPDATEEmpl oy ee SETSal ary=Salary* 1.05
- Toi ncreasethesalar yofonlyoneempl oy eewi thid‘e06’by15%
UPDATEEmpl oy ee SETSal ary=Salary* 1.05 WHEREEI D=’e06’
- Toi ncreasethesalar yofallemploy eesear ningasl arylesst han1000by25%
UPDATEEmpl oy eeSETSal ary=Salar y
* 1.25WHEREsal ar y<1000
129
CREATEVI
EW Emp_
Sal
_1000ASSELECT*FROM Empl
oyee
Aftert
hisquer
yisexecut
ed,
wecanr
unt
hef
oll
owi
ngquer
y,asi
tact
sjustl
i
keanor
mal
tablei
nthedatabase.
SELECT*FROM Emp_
Sal
_1000
- Tocr
eat
eav
iewt
hatcont
ainst
heav
eragesal
aryofempl
oyeesi
neachdepar
tment
.
CREATEVIEW Avg_Sal
ary_
DeptASSELECTDI
D,AVG(
sal
ary)
FROM EmployeeGROUPBYEDI D
General
l
y,anysel
ectst
atementcanbeusedtof
rom avi
ew,
wher ethenaf
tert
hevi
ew
canbeusedasanor maltabl
e.Avi
ewcanalsobeusedi
notherqueri
esasanormal
tabl
e.
JOI NI NGTABLES
Joiningt abl esi ssi milarwi thcombi ningt abl esusi ngt hesel ectst at ementwher ei nt he
condi ti
onweuseequal itybet weenpr imar ykeyat tributesandf oreignkeyat t ri
but es.
Wheni tcomest oJOI N, wewi ll uset hecl auseJOI Nwi t hdi fferentv ari
etyofj oinsl ike
INNER, RI GHTOUTER, LEFTOUTER, etc.inaddi tional lthei ssueswehav eseenf ro
selectst at ementandcr eat ev iewcanbei mpl ement edusi ngt hej oinquer y.Onecanuse
j
oini nnor mal selectst atement .Onecanal sousej oi ni ncr eatingav i
ew.
TheGener al Sy ntax:
SELECT<at tributeList >FROM <t able1>[JOI NTYPE]<t abl e2>
ON<Joi ncondi tion>WHERE<addi t
ional Condi t i
on>
Therear edi fferentt ypesofj oin.
1.InnerJoi n:Joi nsthet abl esusi ngequal itybet weent heat tr
ibut esofpr imar ykeyand
for
eignkeycol umnswher eonl yt uplespar tici
pat ingont her elationshipar ei ncludedi n
theresul t.
SELECT<at tributeList >FROM <t able1>I NNERJOI N<t abl e2>
ON<Joi ncondi t
ion>WHERE<addi ti
onal Condi tion>
1. Lef tJoi n:Joi nsthet abl esusi ngequal itybet weent heat tr
ibutesofpr imar ykeyand
for ei
gnkeycol umnsandal soi ncludest uplesf rom t het abl ei nthel eftint her esult
ev eni ft heydon’ tpar ticipat ei nt her elationshi p.Forat t
ributesf r
om t het ablei nt he
rightsi det hev alue‘ null’wi llbef i
eldf ort hoset uplesf rom t hel eftsi denot
par ti
ci patingi nther elationshi p.
SELECT<at t
ri
but eLi st >FROM <t able1>LEFTJOI N<t able2>
ON<Joi ncondi tion>WHERE<addi ti
onal Condi tion>
2. Ri ghtJoi n: Joinst het ablesusi ngequal i
tybet weent heat tributesofpr i
mar ykey
andf or eignkeycol umnsandal soi ncludest upl esf rom t het abl einther i
ghtsi dein
ther esul tev eni ftheydon’ tpar t
icipatei nther elationshi p.Forat tr
ibut esf rom t he
tabl eint hel eftsidet hev alue‘ nul l
’wi l
lbef iel df ort hoset uplesf rom t her ightsi de
notpar ti
cipat i
ngi nt her elat ionshi p.
SELECT<at t
ri
but eLi st >FROM <t able1>RI GHTJOI N<t able2>
ON<Joi ncondi tion>WHERE<addi ti
onal Condi tion>
130
4.Ful lJoin: Joinsthet ablesusi ngequal it
ybet weent heattri
butesofprimarykeyand
for
eignkeycol umnsandal soincludestuplesf r
om bot htabl
esi ntheresultevenifthey
don’tpar ti
cipatei nther el
ationship.Forat tri
but esf rom thet ableinthel ef
tsidet he
val
ue‘ nul l
’willbef i
eldf orthoset upl
esf rom t het ableinther i
ghtsidenotpar ti
cipat
ing
i
nt her elati
onshi p.AndForat tri
butesfrom t het ableint herightsidethevalue‘null
’wil
l
be fieldf ort hose t uples from t he tablei nt he leftside notpar ti
cipati
ng int he
rel
ati
onshi p.
SELECT<at tr
ibuteLi >FROM <t
st able1>FULLJOI N<table2>
ON<Joi ncondition>WHERE<addi tional Condi t
ion>
Sampl et ablesandExampl est oil
l
ustrat
et hej oint ypes.
EMPLOYEE
EID FName LName Sal
ary EDI
D
e01 Chala Tay e 1500.
0000 d01
e02 Chalt
u mamo 230.
0000 d03
e03 Almaz mitiku 700.
0000 d02
E04 Bekan seleshi 350.
0000 d01
E05 mammo mesf i
n 875.
0000 d03
E06 mahlet takele 1250.
0000 NULL
E07 Olana Kebede 1100.
0000 NULL
DEPARTMENT
DI
D DName DLoc
D01 Finanace B05
D02 Personnel B04
D03 sales B03
D04 Project B07
D05 Mang B01
I
nnerJoi
n
SELECT*FROM empl oyeeINNERJOI Ndepart
ment
ONemployee.edid=depart
ment.
did
Orusingtheali
asmet hod
SELECT*FROM empl oyeeEINNERJOINdepar
tmentD
ONE.edi
d=D.did
TheabovetwoSQLquer ieswillproducethef
oll
owi
ngtabl
e
EID FName LName Sal
ary EDI
D DID DName DLoc
e01 Chala Taye 1500.
0000 d01 d01 Fi
nanace B05
e02 Chalt
u mamo 230.
0000 d03 d03 Sal
es B03
e03 Almaz mit
iku 700.
0000 d02 d02 Per
sonnel B04
e04 Bekan sel
eshi 350.
0000 d01 d01 Fi
nanace B05
e05 mammo mesfi
n 875.
0000 d03 d03 Sal
es B03
Lef
tJoi
n(Lef
tOut
erJoi
n)
131
SELECT*FROM employeeLEFTJOI Ndepart
ment
ONemployee.
edi
d=depart
ment .di
d
SELECT*FROM employeeLEFTOUTERJOI Ndepart
ment
ONemployee.edid=depar
tment.
did
Orusi
ngtheal
iasmet hod
SELECT*FROM employeeELEFTJOI Ndepart
mentD ONE.edi
d=D.
did
SELECT*FROM employeeELEFTOUTERJOI Ndepart
mentDONE.edid=D.
did
Theabov
efourSQLquer
ieswi
l
lpr
oducet
hef
oll
owi
ngt
abl
e
EID FName LName Sal
ary EDI
D DID DName DLoc
e01 Chala Tay e 1500.
00 d01 d01 Fi
nanace B05
e02 Chalt
u mamo 230.
00 d03 d03 sal
es B03
e03 Almaz mitiku 700.
00 d02 d02 Per
sonnel B04
e04 Bekan seleshi 350.
00 d01 d01 Fi
nanace B05
e05 mammo mesf i
n 875.
00 d03 d03 sal
es B03
e06 mahlet takele 1250.
00 NULL NULL NULL NULL
e07 Olana Kebede 1100.
00 NULL NULL NULL NULL
RightJoin(
RightOuterJoin)
SELECT*FROM empl oyeeRI GHTJOI Ndepar t
ment
ONempl oyee.edid=department.
did
SELECT*FROM empl oyeeRIGHTOUTERJOI Ndepar
tment
ONempl oyee.edid=department.
did
Orusingtheali
asmet hod
SELECT*FROM empl oyeeERI GHTJOI Ndepar t
mentD ONE.edi
d=D.
did
SELECT*FROM empl oyeeERI GHTOUTERJOI Ndepart
mentDONE.edid=D.
did
TheabovefourSQLquer i
eswillproducethef
oll
owingt
abl
e
EID FName LName Sal
ary EDI
D DID DName DLoc
e01 Abebe Taye 1500.
0000 d01 d01 Fi
nanace B05
e04 hi
rut sel
eshi 350.
0000 d01 d01 Fi
nanace B05
e03 Almaz mit
iku 700.
0000 d02 d02 Personnel B04
e02 bekel
e mamo 230.
0000 d03 d03 sales B03
e05 mammo mesfi
n 875.
0000 d03 d03 sales B03
NULL NULL NULL NULL NULL d04 Project B07
NULL NULL NULL NULL NULL d05 Mang B01
Ful
lJoi
n(Ful
lOuterJoi
n)
SELECT*FROM employeeFULLJOI Ndepar
tment
ONemployee.
edid=depar
tment.
did
SELECT*FROM employeeFULLOUTERJOI Ndepart
ment
132
ONemploy
ee.
edi
d=depar
tment.
did
Orusi
ngtheali
asmet
hod
SELECT*FROM empl
oyeeEFULLJOINdepart
mentD ONE.
edi
d=D.
did
SELECT*FROM empl
oyeeEFULLOUTERJOINdepart
mentDONE.edi
d=D.
did
Theabov
efourSQLquer
ieswi
l
lpr
oducet
hef
oll
owi
ngt
abl
e
EID FName LName Sal
ary EDI
D DID DName DLoc
e06 mahlet takele 1250.
0000 NULL NULL NULL NULL
e07 bel
ay Kebede 1100.
0000 NULL NULL NULL NULL
e01 Abebe Tay e 1500.
0000 d01 d01 Fi
nanace B05
e04 Bekan seleshi 350.
0000 d01 d01 Fi
nanace B05
e03 Almaz mitiku 700.
0000 d02 d02 Personnel B04
e02 bekel
e mamo 230.
0000 d03 d03 sales B03
e05 mammo mesf i
n 875.
0000 d03 d03 sales B03
NULL NULL NULL NULL NULL d04 Project B07
NULL NULL NULL NULL NULL d05 Mang B01
CREATESAMPLEDATABASE
Thefol
l
owingE/
Rdi
agr
am andt
abl
esar
eusedi
ntheexampl
est
hroughoutt
his
document
.
STUDENT CLASS
STUID LNAME FNAME MAJOR CREDI
TS COURSENUM FACI
D SCHED ROOM
S1001 Smith Tom Hi
stor
y 90 ART103A F101 MWF9 H221
S1010 Burns Edward Ar
t 63 CI
S201A F105 TUTHF10 M110
S1015 Jones Mary Math 42 MTH101B F110 MTUTH9 H225
S1002 Chin Ann Math 36 HST205A F202 MWF11 H221
S1020 Riv
era Jane CI
S 15 MTH103C F110 MWF11 H225
S1025 McCarthy Owen Math 9 CI
S203A F105 MTHF12 M110
FACULTY
FACI
D FACNAME DEPT RANK
F101 Adams Art Prof
essor
F202 Smi t
h Hi
stor
y Associate
F105 Tanaka CI
S I
nstructor
F110 Byrne Math Assi
stant
F221 Bl
ume CI
S Prof
essor
ENROLL
COURSENUM STUID GRADE
ART103A S1001 A
CI
S201A S1020 B
CI
S201A S1002 F
ART103A S1010 I
133
ART103A S1002 D
MTH101B S1020 A
HST205A S1001 C
MTH103C S1010 I
MTH103C S1002 B
CREATETABLESTUDENT
(STUID CHAR(
5),
LNAME CHAR(
10)NOTNULL,
FNAME CHAR(8),
MAJOR CHAR(7)CHECK(
MAJORIN(
'Hi
st'
,
'Ar
t'
,'
CIS'
,
'Mat
h')
),
CREDITS INTEGERCHECK(
CREDI
TS>0),
PRI
MARYKEY( STUI
D))
;
I
NSERTINTOSTUDENTVALUES( '
S1001'
,'
Smi t
h','
Tom',
'Hist'
,90);
I
NSERTINTOSTUDENTVALUES( '
S1010'
,'
Burns','
Edward'
,'Art'
,
63);
I
NSERTINTOSTUDENTVALUES( '
S1015'
,'
Jones' ,
'
Mary',
'
Mat h',
42);
I
NSERTINTOSTUDENTVALUES( '
S1002'
,'
Chin'
,'Ann'
,'
Math',36);
I
NSERTINTOSTUDENTVALUES( '
S1020'
,'
Rivera',
'
Jane'
,'
CIS',15);
I
NSERTINTOSTUDENTVALUES( '
S1025'
,'
McCar t
hy'
,'
Owen' ,
'Math',
9);
CREATETABLEFACULTY
(FACID CHAR( 4),
FACNAME CHAR( 15)NOTNULL,
DEPT CHAR( 15),
RANK CHAR(10)CHECK( RANKI N( 'Professor'
,'
Associ
ate'
,
'
Assi
stant
','
I
nstr
uctor'
))
,
PRI
MARYKEY( FACID));
I
NSERTINTOFACULTYVALUES( '
F101'
,
'Adams' ,
'Art
',
'Professor'
);
I
NSERTINTOFACULTYVALUES( '
F202'
,
'Smi t
h',
'
Hi st
ory '
,'
Associate'
);
I
NSERTINTOFACULTYVALUES( '
F105'
,
'Tanaka',
'CIS'
,'I
nstructor'
);
I
NSERTINTOFACULTYVALUES( '
F110'
,
'Byrne'
,'
Mat h'
,'Assistant
')
;
I
NSERTINTOFACULTYVALUES( '
F221'
,
'Bl
ume' ,
'CIS',
'
Pr ofessor'
);
CREATETABLECLASS
(COURSENUM CHAR( 9),
FACID CHAR(4)REFERENCESFACULTY( FACI
D),
SCHED CHAR(10),
ROOM CHAR(4),
PRI
MARYKEY( COURSENUM));
I
NSERTINTOCLASSVALUES( '
ART103A','
F101','
MWF9',
'H221')
;
I
NSERTINTOCLASSVALUES( '
CIS201A',
'
F105','
TUTHF10',
'
M110');
I
NSERTINTOCLASSVALUES( '
MTH101B' ,
'F110'
,'
MTUTH9','
H225');
I
NSERTINTOCLASSVALUES( '
HST205A','
F202',
'MWF11',
'
H221');
I
NSERTINTOCLASSVALUES( '
MTH103C' ,
'F110',
'
MWF11','
H225');
I
NSERTINTOCLASSVALUES( '
CIS203A',
'
F105','
MTHF12',
'M110')
;
CREATETABLEENROLL
(COURSENUM CHAR( 9)REFERENCESCLASS( COURSENUM) ,
STUID CHAR( 5)REFERENCESSTUDENT( STUID),
GRADE CHAR( 1)CHECK( GRADEI N('A'
,
'B'
,
'C',
'
D',
'F'
,
'I
')
),
PRI
MARYKEY( COURSENUM, STUID));
134
I
NSERTINTOENROLLVALUES(
'ART103A'
,'
S1001',
'A'
);
I
NSERTINTOENROLLVALUES(
'CI
S201A',
'
S1020','
B')
;
I
NSERTINTOENROLLVALUES(
'CI
S201A',
'
S1002','
F')
;
I
NSERTINTOENROLLVALUES(
'ART103A'
,'
S1010',
'I
')
;
I
NSERTINTOENROLLVALUES(
'ART103A'
,'
S1002',
'D'
);
I
NSERTINTOENROLLVALUES(
'MTH101B',
'S1020'
,'
A');
I
NSERTINTOENROLLVALUES(
'HST205A'
,'
S1001',
'C'
);
I
NSERTINTOENROLLVALUES(
'MTH103C',
'S1020',
'
I'
);
I
NSERTINTOENROLLVALUES(
'MTH103C',
'S1002',
'
B');
COMMIT;
135