You are on page 1of 32

UNI

VERSI
TYOFNI
GERI
A,NSUKKA

DEPARTMENTOFCOMPUTERSCI
ENCE

DATABASEDESI
GNANDMANAGEMENT
LABORATORYMANUAL:

DEVELOPEDBY

Dr
.Okor
onkwo,
Mat
thew,
ObayiAdaor
a,Ogbodo,
Ifeoma,
andNzeh,
Royr
ansom

I
ntr
oduct
ion:
Thi
smanualisforDatabaseDevel
opmentandManagementcour
ses;i
tfocusesondesi
gn,
cr
eati
onmanagementandmanipul
ati
onofst
ruct
uresanddat
a.

Requi
rement
sfort
hePr
act
icalSessi
ons:
Forastudentt
oderi
veful
lbenef
it
sfr
om thi
smanual,He/Sheshoul
dhaveaper
sonalcomput
er
i
nstal
ledwithaRel
ati
onalDat
abaseManagementSystem (
RDMS).

Obj
ect
ives:
Theoveral
lobject
ivesofthi
smanualaret
oenabl
ethet
utorsandst
udentsapply,
demonstr
ate
andtestthestudent,under
standi
nganduseoft
hetheori
esandconceptstaughtdur
ingthe
cl
assroom sessi
ons.
Eachsectionisst art
edwi thdefi
nit
ionori ntroduct
ionofkeyconcept
st oremindt he
studentoft he classroom lecture,iti
st hen foll
owed wi t
h questi
on t
otestthe student
understandi
ng.Itistheref
oreexpect edt
hatstudentsshouldfrequent
lymaker
efer
encetobot h
recommendedt extbooksandl ecturenot
esgivenbyt helect
urers.

Lear
ningOut
come:
Att
heendofeachsect
ionoft
hel
abor
ator
yexer
cises,
thest
udentshoul
dbeabl
eto:
 Demonst
rat
eunder
standi
ngoft
hekeyconcept
sandt
ermi
nol
ogi
es
 Appl
ythet
heor
iest
othesol
uti
onofr
eall
if
echal
lenges
1 I
ntr
oduct
ionofBasi
cConcept
sandKeywor
ds
Centraltothi
scour seisDATA.Thecour sefocusisonacquir
ingandmanagi ngnecessar
ydat a
aboutor ganisati
ons and somet imes indivi
dual
sf oruse in addressi
ng chall
enges and
reposit
ioni
ngt hem foebet
teref
fi
ciency.Nexttodataacqui
sit
ioni
smanagement( manipulat
ion)
toyieldnecessaryInformati
on.Sol etuslookatthesethr
eeconcepts:dat
a,managementand
Inf
ormat i
on

Data
Dataar efactsorposi t
iveasser ti
onsaboutsomedomai nofdi scourse(i
nter
est)
.Datum isa
unitofdata;thatisasymbolorasetofsymbol susedtor epresentsomethi
ng.Thisrel
ati
onship
betweensymbol sandwhatt heyr epresentistheessenceofwhatwemeanbyi nfor
mat i
on.
Hence, i
nformationi si
nterpret
eddat a;datasuppliedwit
hsemant i
cs.
Bothdat aandi nformationar eembodi edi
nt heconceptofsign;hencesignsandsign-
systemsar ethef undament alstuffofdatabasesystems.
A sign-syst em i
sanyor ganisedcollect
ionofsi gns.Themostcommonexampl ei s
everydayspokenl anguage.

Dat
abase
Databaseisanor gani
sedcollect
ionofdat
awhichismeantt orepresentsomeuni ver
seof
discour
se ata parti
cularpointintime.I
ti sther
ef e,an or
or gani zed,machi ne-
readabl
e
coll
ectonofsymbol
i s,t
obei nt
erpr
etedasatr
ueaccountofsomeenterprise.Thi
siswherethe
managementissuescomei n.
Theor
gani
zed,machine-r
eadabl
ecol
lect
ionofsymbol
siswhatyou“
see”i
fyou“
lookat

adat
abaseatapart
icul
arpointi
nti
me.

Sol
uti
ont
oExer
cises
E1.
1Whati stheal
ter
nat
ivedef
ini
ti
on(
view)ofdat
abaseandst
atet
hef
unct
ions/
rol
esof
dat
abases
Thevi hatadat
ew t abaseisacol l
ect
ionofvariableswhichr ef
lectst
hefactt
hattheaccount
(storyordescr
ipt
ion)offori
nstanceanenter
prise,changesfrom timetoti
medependi
ngont he
frequencyofchangeinthedetail
swechooset oincludeinthataccount.

Funct
ion-adat
abasei
sasetofpr
ogr
amst
hatpr
ovi
dest
hef
oll
owi
ngser
vices:
o St
orageofst
ruct
ureddat
a
o Accessandupdat
eoft
hisdat
a
o Sear
chi
ngoft
hisdat
a
o Guar
ant
eeACI
D(At
omi
c,Consi
stent
,Isol
ati
on,
Dur
abi
li
ty)t
ransact
ions
o Ensur
esdat
adoesn’
tgetl
ostorover
wri
tt
en
o Admi
nist
rat
ionofdat
a
 Accesscont
rol
,backups

E1.
2Explain/
Defi
nethefol
lowi
ngDat
abasesConcept
s/Ter
ms:DBMS,
Met
adat
a,Dat
a-
di
cti
onaryandFiel
d
DBMS(
Dat
abaseManagementSyst
em)
o ADBMSi
sacol
lect
ionofi
nter
-rel
ateddat
aandsetofpr
ogr
amst
omani
pul
atet
hose
dat
a.
o DBMS=Dat
abase+Setofpr
ogr
ams
Met
adat
a
o Met
adat
aisdat
aaboutdat
a.
o Datasuchastabl
ename,col
umnname,datat
ype,
aut
hori
zeduseranduseraccess
pr
ivi
legesf
oranytabl
eiscal
ledmet
adat
afort
hatt
abl
e.
Dat
adi
cti
onar
y
o Dat
adi
cti
onar
yisani
nfor
mat
ionr
eposi
tor
ywhi
chcont
ainsmet
adat
a.
o I
tisusual
lyapar
toft
hesyst
em cat
alog.
Fi
eld
o Af
iel
disachar
act
erorgr
oupofchar
act
erst
hathaveaspeci
fi
cmeani
ng.
o I
tisal
socal
ledadat
ait
em.I
tisr
epr
esent
edi
nthedat
abasebyaval
ue.
o ForExampl
ecust
omeri
d,name,
soci
etyandci
tyar
eal
lfi
eldsf
orcust
omerDat
a.

E1.
3Diff
erent
iat
ebet
weenSt
ruct
uredandUnst
ruct
ureddat
a,andgi
vef
ourexampl
esofeach
t
ype.
 Str
uctur
eddataishighl
y-or
gani
zedandf
ormat
tedi
nawaysoi
t'
seasi
lysear
chabl
ein
rel
ati
onaldat
abases.
 Unst
ruct
ured dat
a has no pr
e-def
ined 
for
mat
 oror
gani
zat
ion,maki
ng i
tmuch mor
e
di
ff
icul
ttocol
lect
,pr
ocess,
andanal
yze
Examplesofstr
uct
ureddat
aincl
udenames,dat
es,addr
esses,cr
edi
tcar
dnumber
s,st
ock
i
nformati
on,
etc.
Exampl es ofUnst r
uctured dat
ai ncl
ude:photos and graphicimages,videos,st
reaming
i
nst r
umentdata,WebPages,PDFf i
les,PowerPoi
ntpresent
ations,email
s,bl
ogsentri
es,wiki
s
andwor dprocessingdocument s/
texts,vi
deo,audi
o,mobi l
eact i
vit
y,soci
almediaactivit
y,
satell
it
eimagery,survei
ll
anceimagery

E1.
4Explaint
hef
oll
owi
ngdr
awbacksoft
heConvent
ionalf
il
e-baseddat
amanagement
syst
em:
Redundancy,
Inconsi
stency,
Limi
tedshar
ingandSecur
it
ypr
obl
ems
Dat
aRedundancy
o Oft
enthesamei nfor
mati
oni
sdupli
cat
edi
ndif
fer
entfi
les.Thi
sleadst
odat
adupl
icat
ion
(
redundancy)whichint
urnr
esul
tsi
nmemorywastage
Dat
aInconsi
stency
o Duet
odat
aredundancy,
ther
eispossi
blet
hatdat
amaynotbei
nconsi
stentst
ate.
o Forexampl
e,considert
hatanaddressofsomecust omerchanges.And,thatcust
omer
hasbothki
ndsofaccounts.Now,i
tispossibl
et hatt
hischangedaddressisupdatedi
n
onlyonef
il
e,leavi
ngaddressi
notherfi
leasiti
s.Asar esul
tofthi
s,samecust omerwi
ll
havetwodif
ferentaddr
essesi
ntwodi f
fer
entfi
les,makingdatai
nconsist
ent.
Li
mit
edDat
aShar
ing
o Dat
aar
escat
ter
edi
nvar
iousf
il
es.
o Dif
ferentf
il
esmayhavedif
fer
entfor
mat s.So,
duet
othi
sdat
aisol
ati
on,
iti
sdi
ff
icul
tto
sharedataamongdif
fer
entappl
icat
ions.

Secur
it
yPr
obl
ems
o Datashoul
dbeaccessi
bletousersi
nalimi
tedwayandeachusershoul
dbeal
lowedt
o
accessdat
aconcer
ninghisappl
icat
iononl
y.
o But
,infi
leprocessi
ngsyst
em,appl
icati
onprogr
amsar eaddedi
nanadhocmannerby
di
ff
erentpr
ogr ammers,
makingi
tdi
f f
icul
ttoenf
orcesuchki
ndofsecur
it
yconst
rai
nts.

Dat
abaseAppl
icat
ions
Anymedium t
olar
gesizedor
ganizat
iontodayusedat
abases.Busi
nessesjustdonotscal
e
wit
houtusi
ngthem.Onceabusinessgetslar
gert
hanthe“ma&pa”st age,
itstar
tst
oneedone
ormoredat
abasestomanagethebusiness

E1.
5 Useasent
enceeacht
oexpl
ainhowdat
abasei
susedi
nanyf
ourAppl
icat
ionar
eas
 Air
li
nesandr ai
lways-useonl
inedat
abasesf
orr
eser
vat
ion,andf
ordi
spl
ayi
ngt
he
schedul
einf
ormati
on.
 Banki
ng-usedat
abasesf
orcust
omeri
nqui
ry,
account
s,l
oans,
andot
hert
ransact
ions.
 Educat
ion-School
susedat
abasesf
orcour
ser
egi
str
ati
on,
resul
t,andot
heri
nfor
mat
ion.
 Tel
ecommunicat
ions-usedatabasestostor
ei nf
ormationaboutt
hecommuni
cat
ion
net
work,
tel
ephonenumber
s,r
ecordofcal
ls,
forgenerat
ingmonthl
ybil
ls,
etc.
 Cr
edi
tcardt r
ansact
ions-useddat
abaseskeept
rackofpur
chases,cr
edi
t,gener
ate
mont
hlyst
atements.
 E-commer ce-I
ntegr
ateshet
erogeneousi
nfor
mat
ionsour
ces(
forexampl
e,cat
alogs)f
or
business
 Healt
hcare-Dat
abasesar
eusedf
ormai
ntai
ningt
hepat
ientheal
thcar
edet
ail
sin
hospi
tal
s.
 Digi
tall
ibr
ari
esanddigi
talpubl
ishi
ng- usedf
ormanagementanddel
iver
yofl
arge
bodi
esoftext
ualandmul
timedi
adata.
 Fi
nance-forstor
ingi
nfor
mat
ionsuchassal
es,pur
chasesofst
ocksandbondsordat
a
usef
ulforonl
inet
radi
ng.
 Sal
es-usedt
ost
orepr
oduct
,cust
omerandt
ransact
iondet
ail
s.
 Humanr esour
ces-Organi
zati
onsusedatabasesf orst
ori
ngi nf
ormat
ionaboutt
hei
r
empl
oyees,sal
ari
es,
benefi
ts,
taxes,
andf
orgenerat
ingsal
arychecks.

2. DATAMODELS
Everydatabasemustadheretot
heprinci
plesofsomedat amodel.I
ndatabasel
it
erat
ure,t
he
term dat
amodeli susedi
nanumberofdiff
erentsenses,t
woofwhicharethemostimport
ant:
thatofarchi
tect
uref
ordat
a,andt
hatofanintegr
atedsetofdat
arequi
rements.

High-
levelConcept
ualDataModel s-pr ovi
desconceptsforpresent
ingdatainwayst
hatare
cl
osetothewaypeopl eper
ceivedata.Atypi
calexampleistheenti
tyrel
ati
onshi
pmodel
,which
usesmainconceptsli
keenti
ti
es,at
tri
butesandrelat
ionshi
ps.

Dat
aModel
li
ng
Thisi
sthefi
rststepi
ntheprocessofdatabasedesign.Thi
sst
epissometi
mesconsider
edt o
beahigh-l
evelandabstr
actdesignphase,al
soreferr
edtoasconcept
ualdesi
gn.Theaim of
thi
sphasei
stodescri
be:
 Thekeyent
it
iesi
nthedat
abase(
e.g.
,ent
it
ies:st
udent
s,l
ect
urer
s,cour
ses,
subj
ect
s)
 Therel
ati
onshi
psbet
weent
hem (
e.g.
,st
udent
sar
esuper
visedbyl
ect
urer
s;l
ect
urer
steach
cour
ses)
 Theconstr
aint
sonent
it
ydat
a(e.
g.,st
udentnumberhasexact
lyei
ghtdi
git
s;acour
sesi
x
l
ett
ercodes)

E2.
1Wi
thexampl
esexpl
aint
hef
oll
owi
ngdat
amodelt
erms:ent
it
y,at
tri
but
esandr
elat
ionshi
p
Ent
it
yrepr
esent
sar
eal
-wor
ldobj
ectsuchempl
oyee,
proj
ect
,cour
se,
book,
etc.
At
tri
but
esr
epr
esentpr
oper
ti
essuchasanempl
oyee’
sname,
addr
essandbi
rt
h-dat
e.
Rel
ati
onshiprepr
esentsanassoci
ati
onamongent i
ti
es:anempl
oyeewor
ksonmanypr
oject
s.
Arel
ati
onshipexi
stsbetweent
heemployeeandeachproject
.

E2.
2.Withsuit
abl
ediagrams,di
ff
erent
iat
ebet
weent
hef
oll
owi
ngdat
amodel
s:Rel
ati
onal
,
Net
workandHier
archi
cal

TheRelati
onalmodelrepresent aasr
sdat el
ati
ons,ortabl
es,asshowbelow.Forexample,the
automati
ctel
lermachine(ATM)car dhasPin-Code,expir
ydateandaccountinfor
mationofa
bankcustomer.Thecustomer sarei
ndivi
dualssuchasMi chael
,Matthew,Ada,Dorot
hy,Agu.
Eachcustomerrecor
dissaidtobeani nst
anceoftheATM- Cardt
able.
Cust
ome Sex Pi
n-code Exp-
dat
e
r
Mi
chael Mal
e 0990 22/
01/
20
22
Ada Feaml
e 1551 05/
05/
20
19
Agu Mal
e 6161 23/
03/
20
22
Dor
othy Femal
e 3001 17/
12/
20
20

TheNetwor
kmodelrepresent
sdat
aasr ecor
dtypes.Themodelr
epr
esent
sal
imi
tedt
ypeof
one-
to-
manyrel
ati
onshi
pscaledasett
l ype,asshowninFig.A.
Fi
g.A:Net
wor
kmodeldi
agr
am. Fi
g.B:Hi
erar
chi
calmodeldi
agr
am

TheHi erarchi
calmodelr
epresent
sdataasint
reest
ruct
ure.Eachbranchofthehier
archy
representsanumberofrel
atedrecor
ds.Fi
g.Bshowsthi
sschemai nhier
archicalmodel
notati
on.

E2.
3 St
ate(
orsummar
ize)t
heRel
ati
onalDat
abaseDesi
gnpr
ocess
 St
ep1:Def
inet
hePur
poseoft
he 
Dat
abase 
(Requi
rementAnal
ysi
s).
..
 St
ep2:Gat
herDat
a,Or
gani
zei
n t
abl
es 
andSpeci
fyt
hePr
imar
yKeys..
..
 St
ep3:
 Cr
eat
e Rel
ati
onshi
psamong 
Tabl
es..
..
 St
ep4:Ref
ine&Nor
mal
izet
he 
Desi
gn.

E2.
4Wi t
hr espectt
ot he abst
ract
ion l
evel
,st
atet
he di
ff
erence bet
ween:Ext
ernaland
Concept
ualmodel
s.
Ext
ernalmodel
s
 Repr
esentt
heuser
’svi
ewoft
hedat
abase
 Cont
ainmul
ti
pledi
ff
erentext
ernalvi
ews
 Ar
ecl
osel
yrel
atedt
other
ealwor
ldasper
cei
vedbyeachuser

Concept
ualmodel
s
•Pr
ovi
def
lexi
bledat
a-st
ruct
uri
ngcapabi
li
ti
es
•Pr
esenta“
communi
tyvi
ew”
:thel
ogi
calst
ruct
ureoft
heent
ir
edat
abase
•Cont
aindat
ast
oredi
nthedat
abase
•Showr
elat
ionshi
psamongdat
aincl
udi
ng:
Const
rai
nts
Semant
ici
nfor
mat
ion(
e.g.
,busi
nessr
ules)
Secur
it
yandi
ntegr
it
yinf
ormat
ion
 Consi
der
sadat
abaseasacol
lect
ionofent
it
ies(
obj
ect
s)ofvar
iouski
nds
 Ar
ethebasi
sfori
dent
if
icat
ionandhi
gh-
leveldescr
ipt
ionofmai
ndat
aobj
ect
s;nott
he
det
ail
s
 Ar
edat
abasei
ndependentr
egar
dlessoft
hedat
abaseyouwi
llbeusi
ng

E2.
5Dr
awt
het
hree-
level
sofdat
amodelwi
tht
hephysi
caldat
aor
gani
sat
ion

E2.
6.Useonesent
encet
odef
ineorexpl
aint
hef
oll
owi
ng:
Hi
erar
chi
calmodel
: r
epr
esent
sdat
aasahi
erar
chi
calt
reest
ruct
ure
I
nst
ance I
sar
ecor
dwi
thi
nat
abl
e/Rel
ati
on
Net
wor
kmodel
: Repr
esent
sdat
aasr
ecor
dtypes
Rel
ati
on I
sanot
hert
ermf
ort
abl
e
Rel
ati
onalmodel Repr
esent
sdat
aasr
elat
ionsort
abl
es
Sett
ype: I
sal
imi
tedt
ypeofonet
omanyr
elat
ionshi
p
Ent
it
y r
elat
ionshi
p Is a data modelthatdescr
ibes a dat
abase showi
ng t
abl
es,
di
agram att
ri
butesandrel
ati
onshi
ps
Ext
ernalmodel Repr
esent
stheuser
’svi
ewoft
hedat
abase
I
nter
nalmodel I
sar
epr
esent
ati
onoft
hedat
abaseasseenbyt
heDBMS
Logi
cal dat
a Theabili
tyt ochanget
hel
ogi
calschemawi
thoutchangi
ngt
he
i
ndependence ext
ernalschema
Physi
cal dat
a Theimmuni
tyoft
hei
nter
nalmodelt
ochangesi
nthephysi
cal
i
ndependence model
Physi
calmodel Thephysi
calr
epr
esent
ati
onoft
hedat
abase
Schema I
sanover
alldescr
ipt
ionofadat
abase
Logi
caldesi
gn Wher
eyoucr
eat
eal
lthet
abl
es,
const
rai
nts,
keys,
rul
es,
etc.
Logi
calschema I
s a concept
ualdesi
gn oft he dat
abase done on paperora
whi
teboar
d,muchli
kearchi
tectur
aldr
awingsforahouse
E2.
7Descr
ibeDat
aModelas:Ar
chi
tect
ureandI
ntegr
atedsetofr
equi
rement
s(Bl
uepr
int
)

Dat
aModelas:Ar
chi
tect
ure
Theter
m dat
amodelisusedtorefert
oasetofgener
alpr
inci
plesf
orhandl
ingdat
a.Thi
ssetof
pri
nci
plesmaybedi
videdi
ntothreemajorpar
ts:
 Dat
adefi
nit
ion-def i
ninganor
gani
sat
ionf
ordat
a;asetofpr
inci
plesconcer
nedwi
th
howdat
aisstruct
ured.
 Dat
amani pul
ati
on-concer nshow thedat
aisaccessedandhow i
tischangedi
nthe
dat
abase;asetofpr
inci
plesconcer
ninghowdat
aisoperat
edupon
 Dat
ai nt
egri
ty-asetofpr
inci
plesconcer
nedwit
hdeter
mini
ngwhi
chst
atesar
eval
idf
or
adatabase,
iti
sver
ymuchl i
nkeddatamanipul
ati
on.

Dat
aModelasBl
uepr
int
Theterm datamodeli
salsousedt orefert
oani ntegr
ated,
butimplement
ati
onindependent,
set
ofdatar equir
ementsforsome appl ication.Forexample,we speak oforder-pr
ocessi
ng,
accounts-r
ecei
vabl
e,orstudent-
admi ssionsdat amodels.Dat amodelinthissensei san
i
mpor t
antcomponentpartofanyinformationsystemsspecif
icat
ion.

E2.
8Useonesent
enceeacht
oexpl
aint
hef
oll
owi
ngDat
aModel
stypes:Pr
imi
ti
ve,
Classi
c
andSemant
ic
Wemaymakeadi
sti
nct
ionbet
weent
hreegener
ati
onsofar
chi
tect
uraldat
amodel
:
1. Pr
imit
ivedatamodels.Inthi
sappr
oachobject
sarerepresentedbyr ecor
dst
ruct
ures
gr
oupedinfi
le-
str
uct
ures;t
hemai
noperat
ionsar
ereadandwr i
terecor
ds
2. Cl
assi
cdat
amodel
s.Thesear
ethehi
erar
chi
cal
,net
wor
kandr
elat
ionaldat
amodel
s.
3. Semanti
cdat amodels.Thi
sgivesmeaningt ot
heinformati
oninthedatabase;semant
ics
i
s notr eadil
y apparentfrom the database i
tself
.Semant i
ci nf
ormation mustbe
consci
ouslyappl
iedbytheuserofdat
abasesusingt hecl
assicappr
oach.

TheGoal
/I
mpor
tanceofdat
aModel
li
ng
Thegoaloft hedatamodeli st omakesur ethatallt
hedataobj ect
sr equiredbyadat abasear e
compl etelyandaccur at
elyrepresent
ed.Becausedat amodelusual lyisdet ai
ledenough,i t
’s
usedbyt hedat abasedevel opersasa“ bl
uepri
nt”forbui l
dingthephysi caldat abase.The
i
nfor mationi tcontainsisusedt odefi
net herel
ati
onaltables,t
hepr i
mar yandt hef oreignkeys,
stored pr ocedures,and t ri
gger s.Therefor
e,withoutcar ef
ulplanni ng,one may cr eatea
databaset hatomi t
sdat arequiredtocreatecri
ti
calreport
s,butratherpr oducer esultsthatare
i
ncor rectori nconsistent
,andi sunabl
etoaccommodat echangesinuser ’srequirement s.

E2.
9Useonesent
enceeacht
oexpl
ainanyf
ouressent
ialchar
act
eri
sti
csofgooddat
amodel

Thef
oll
owi
ngar
ethechar
act
eri
sti
csofagoodDat
aModel
:
a.Compl
eteness-suppor
tal
lnecessar
ydat
a
b.Nonredundancy-notspeci
fyadat
abasei
nwhi
cht
hesamef
actcoul
dber
ecor
ded
morethanonce.
c.Enf
orcementofBusi
nessRul
es-r
efl
ect
sandenf
orcest
her
ulest
hatappl
ytot
he
busi
nessdat
aaccur
atel
y.
d.Dat
aReusabi
li
ty:t
hedat
ast
oredi
nthedat
abasear
ereusabl
ebeyondt
hoseant
ici
pat
ed
i
nthepr
ocessmodel
e.Stabi
lit
yandFl
exi
bil
it
y:shoul
dcopewi
thpossi
blechangest
othebusi
ness
requi
rement
s.
f
. El
egance:shoul
dpr
ovi
dear
easonabl
eneatandsi
mpl
ecl
assi
fi
cat
ionoft
hedat
a.
g.Communicati
on:t
hemodelsupport
seffect
ivecommuni
cat
ionamongt
hevar
ious
st
akehol
dersi
nthedesi
gnofthesystem.
h.I
ntegrat
ion-thepr
oposeddat
abaseshoul
dfi
twel
lwi
tht
heor
gani
zat
ion’
sexi
sti
ngand
f
uturedatabase

3. Dat
abaseDevel
opment
Databasedevelopmenti
sgenerall
yaprocessofmodell
ing;aprocessofsuccessi
ver
efi
nement
t
hroughthreelevel
sofmodel:concept
ual
,logi
calandphysical
.

E3.
1Statethefocus/concer
n ofeach t
her
efi
nementpr
ocessand dr
aw t
hesuccessi
ve
r
efi
nementcycl
e

TheConcept
ual-i
samodeloft
her
ealwor
ldexpr
essedi
nter
msofdat
arequi
rement
s.
TheLogical-isamodeloft herealworl
dexpressedi
nter
msofthepri
ncipl
esofsomedata
model;i
ti sconcernedwithdeter
miningthecontent
sofadatabaseindependent
lyoft
he
exi
genci
esofapar t
icul
arphysi
cali
mplementat
ion.
ThePhysical-i
samodeloft
herealwor
ldexpr
essedi
ntermsoft
heconstr
uct
sofsomeDBMS.
I
tist
hetransfor
mat
ionoft
helogi
calmodelusi
ngaspeci
fi
csof
tware/
har
dwareconf
igur
ati
on.
Theconcept ualmodell
ing i
ssomet i
mesr egar
ded asastageheaded byar equi
rements
el
icit
ati
on;processi
nvolvi
ngelici
tingthesetofdataandprocessi
ngrequi
rementsf
rom the
users(keyactor
softhedatabase).Thusthestagecanbet
houghtofascompr i
singt
wosub-
stages.

Dat
abaseEnvi
ronment
The f
undament alpoi
ntoft he ANSI
-SPARC repor
ti sthe i
dent
if
icat
ion ofthree l
evel
s of
abst
ract
ioni.e.thethreel
evel
satwhichdatai
temscanbedescr i
bed.Theset hr
eelevelsgave
ri
setoathree-levelar
chit
ect
uremadeupofexternal
,concept
ual
,andint
ernall
evel
s.
Thefundamentalobject
iveofthethr
ee-
levelarchi
tect
ure,ofadatabaseenvi
ronment,i
s
t
o separat
e each user’
s view ofthe dat
abase fr
om t he wayt he dat
abase i
s physi
call
y
r
epresent
ed.

E3.
2 Expl
ainanyt
wor
easonsf
orsepar
ati
ngeachuser
’svi
ewoft
hedat
abase
1. ForConsi
stencyandIntegri
tyinaccessi
ngdata:eachusershoul
dbeabletoaccesst
he
samedata,butcanenjoyadi f
fer
entcustomi
zedview ofthedat
a,andchangetheway
he/shevi
ewst hedat
a,withoutnecessar
il
yaff
ecti
ngotheruser
s.
2. ForDatabaseI ndependence:thisensurethatusersshoul
ddonotdealdirect
lywith
physi
caldatabasestoragedetai
ls.Inotherwords,
auser’
sint
eract
ionwi
tht
hedatabase
shoul
dbei ndependentofstor
ageconsiderati
ons.
3. Fl
exibil
it
y: TheDBAshoul dbeabletochanget
hedat
abasest
orageandconcept
ual
st
ructureswit
houtaf
fect
ingtheuser
’svi
ews.
4. Maintai
nabi
li
ty: Theinter
nalstruct
ureofthedatabaseshoul
d notbeaf
fect
ed by
changestothephysicalaspect
sofst or
age,suchaschangeovertoanew st
orage
devi
ce.

3.
1 Ent
it
yRel
ati
onshi
pModel
li
ng(
ERM)
Thetwomajormethodol
ogi
esusedt
ocr
eat
eadat
amodelar
e:Ent
it
y-Rel
ati
onshi
p(ER)and
Obj
ectModelappr
oaches.

Enti
ty–rel
ati
onshipmodelli
ng(ERM)appr oachisat op-downdesigntechnique,whi
chinvol
ves
repr
esenti
ngsomeuni ver
seofdiscourseintermsofi t
senti
ti
esandr el
ati
onships.
TheERM viewstherealworldasaconst ructofenti
ti
esandassoci ati
onbetweenthem.
TheERM constructsar
e:Enti
ty,
Relati
onship,At
tr
ibutes,andIdent
if
ier
s.

Ent
it
ies
Ent
it
iesar
ethepr
inci
paldat
aobj
ectaboutwhi
chi
nfor
mat
ioni
stobecol
lect
ed.Ent
it
iesar
e
usual
lyr
ecogni
zabl
econcepts,ei
therconcret
eorabst
ract
,suchasper
son,
places,
thi
ngs,
or
event
swhichhaver
elevancetothedatabase.
Anenti
tyisanal
ogoustoatableintherel
ati
onalmodel
.Ent
it
iesar
eclassif
iedasindependent
.Ani
ordependent ndependententi
tyisonethatdoesnotr
elyonanotherfori
denti
fi
cati
on.A
dependentent
it
yisonet
hatr
eli
esonanot
herf
ori
dent
if
icat
ion.
At
tri
butes-descr
ibetheenti
tywhi
cht heyareassoci
ated;t
heyar
epr
oper
ti
esusedt
o
di
sti
nguishoneenti
tyi
nstancef
rom another
.

E3.
3 Expl
aint
hef
oll
owi
ngERt
ermi
nol
ogi
es:Occur
rence,
Associ
ati
veent
it
y,Subt
ypesent
it
y

a.Enti
tyOccur
rence:(
alsocall
edaninstance)i
sani
ndi
vidualoccur
renceofanent
it
y;i
tis
anal
ogoustoarowi ntherel
ati
onalt
able.
b.Associ
ati
veent
it
ies(
alsoknownasint
ersect
ionenti
ti
es)ar
eentit
iesusedt
oassoci
ate
t
woormor eent
it
iesi
nordertor
econci
leamany- t
o-manyrelat
ionshi
p.
c.Subtypesent
it
iesareusedingenerali
zati
onhier
archiest
orepr
esentasubsetof
i
nstancesoft
heirparentent
it
y,call
edthesupert
ype,butwhi
chhaveatt
ri
butesor
rel
ati
onshi
psthatapplyonlytothesubset
.

E3.
4AnOr gani
sati
onwantstokeepr ecor
dsabouti
tsSt
affandBui
ldi
ngs,
li
statl
eastf
ive
at
tri
but
esforeachoft
heentit
ies.

St
aff
-At
tri
butes:St
aff
D, Fi
rstName,LastName,Dept
,dat
eofbi
rt
h,Ci
ty,
LocalGover
nment
Ar
ea,St
ate,DateofFir
stAppoint
ment,,et
c.

Bui
ldi
ngAt
tr
ibut
es:Bui
ldI
D,Owner
,Descr
ipt
ion,
Locat
ion,
Type,
Cost

Rel
ati
onshi
ps
A Relati
onshi prepresentsanassociati
onbet weent woormor eent i
ti
es.Anexampl eofa
rel
ati
onship woul d be:empl oyees are assigned to project
s,pr oj
ects have subtasks
departments manage one ormor e pr
oject
s Relati
onships are cl
assi
fi
ed byt hei
rdegr ee,
connectivi
ty,car
dinali
ty,di
rect
ion,t
ype,andexistence.Notallmodeli
ngmet hodol
ogiesuseal l
theseclassif
icat
ions.

ERDi
agr
am Not
ati
ons
Thereis no st andardfor represent
ing data object
si n ER diagrams.Each model ing
methodologyusesi t
sownnot at
ion.However,thereareanumberofnot at
ionsusedtoday;
amongt hemorecommonar eBachman, cr
ow'sfoot
,andIDEFI
X.Allnotati
onalstyl
esrepr
esent
enti
ti
esasr ect
angularboxesandr elat
ionshi
psasl i
nesconnecti
ngboxes.Eachst yl
eusesa
speci
alsetofsymbolstorepr
esentt hecardi
nali
tyofaconnect
ion.

E3.
5Useadi agram t
oshowthesymbolsusedtorepr
esentt
hefoll
owingtermsi
nERdiagram
andexpl
aineachone:Ent
it
y,Rel
ati
onshi
p,Cardi
nal
it
y,Att
ri
bute,
Exist
enceandI
denti
fi
er

Thedi
agr
am ofERconst
ruct
s:
a.Ent
it
iesar
erepr
esentedbylabeledr
ect
angl
es.Thel
abeli
sthenameoft
heent
it
y.Ent
it
y
namesshoul
dbesingularnouns.
b.Relat
ionshi
psarerepr
esentedbyasol i
dli
neconnect
ingt
woenti
ti
es.Thenameoft
he
rel
ati
onshipiswr
it
tenabovethel
ine.Rel
ati
onshi
pnamesshoul
dbeverbs.
c.Att
ri
but
es-ar el
istedi
nsidetheent
it
yrect
angl
e;i
dent
if
ier
sar
eunder
li
ned.At
tr
ibut
e
namesshoul
dbesingul
arnouns.
d.Car
dinal
it
y:Many-isrepresent
edbyal
ineendi
ngi
nacr
ow'
sfoot
.Ift
hecr
ow'
sfooti
s
omit
ted,
thecar
dinal
it
yisone.
e.Exi
stence i
sr epresent
ed by pl
aci
ng a cir
cle ora perpendicul
arbaron t he l
ine.
Mandatoryexi
stenceisshownbythebar(
|)nexttotheent
ityforaninst
anceisrequi
red.
Opti
onalexi
stenceisshownbyplaci
ngacircl
enexttotheenti
tythatisopt
ional
.

El
imi
nat
ingRedundantRel
ati
onshi
ps
Aredundantrelat
ionshi
pisarel
ati
onshi
pbet
weentwoenti
ti
est
hatisequival
enti
nmeaningto
anotherr
elat
ionshipbetweent
hosesametwoenti
ti
esthatmaypassthroughanint
ermedi
ate
enti
ty.

Nor
mal
izat
ion
Normali
zat
ionispartofthedat
abasedesi
gnprocess.However,
iti
sdiff
icul
ttosepar
atet
he
normal
izat
ionprocessfr
om theERmodell
ingprocesssothetwotechni
quesareused
concur
rent
ly.
Nor
malizat
ionist
hebr
anchofrel
ati
onalt
heorythatprovi
desdesi
gni
nsi
ght
s.I
tist
he
pr
ocessofdet
ermini
nghowmuchredundancyexist
sinat abl
e.
Thegoal
sofnor
mal
izat
ionar
eto:
•Beabl
etochar
act
eri
zet
hel
evelofr
edundancyi
nar
elat
ionalschema
•Pr
ovi
demechani
smsf
ort
ransf
ormi
ngschemasi
nor
dert
oremover
edundancy

Normal
izi
ngal ogicaldatabasedesi
gninvol
vesusi
ngformalmethodstoseparat
ethedatainto
mult
ipl
e,rel
atedtablesmadeupofanumberofnar rowtables(
wit
hfewercolumns);t
hisi
st he
char
acter
ist
icofanor mali
zeddatabase.Afew wi
detables(wi
thmorecolumns)charact
erise
nonnormali
zeddat abase.
Reasonabl
enormal
izat
ionoft
enimpr
ovesperf
ormance.I
tisathr
eest
eptechni
quethat
pl
acesthedat amodeli
nto:fi
rst
,secondandthi
rdnormalforms.Whenusef
ulindexesare
avai
labl
e,t
hequer
yopt
imi
zeri
sef
fi
cientatsel
ect
ingr
api
dandef
fi
cientj
oinsbet
weent
abl
es.

E4.
1 St
atet
hef
eat
ureandwhati
sachi
evedwhenar
elat
ioni
sin:1st,2nd,and3rd Nor
mal
For
ms
Fi
rstNor
malFor
m(1NF)
Inthefi
rstnormalform, onlysinglevaluesar epermi
tt
edattheintersect
ionofeachrowand
column;hence, t
herear enor epeati
nggr oups.Herei
narelati
ont hatcontai
nsarepeat i
ng
group,t
her epeati
nggr oupi sremovedandf ormsnewrel
ations.ThePKoft henewr elati
onmay
beacombi nat
ionofthePKoft heori
ginalrelat
ionpl
usanat t
ri
butefrom thenewlycreated
rel
ati
onf oruniqueidentif
icati
on.

SecondNor
malFor
m(2NF)
hesecondnor
Fort malfor
m, t
herel
ati
onmustf
irstbei
n1NF.Ther
elat
ioni
saut
omat
ical
lyi
n
2NFif
,andonl
yif
,thePKcompri
sesasingl
eat
tr
ibute.
Ift
herel
ati
onhasacomposit
ePK,theneachnon- keyat
tr
ibut
emustbeful
lydependentont
he
enti
rePKandnotonasubsetoft
hePK( i
.e.
,ther
emustbenoparti
aldependencyor
augmentat
ion)
.

Thi
rdNor
malFor
m(3NF)
Tobei nthi
rdnormalfor
m,therel
ati
onmustbeinsecondnor
malform.Alsoal
ltr
ansit
ive
dependenciesmustberemoved;anon-
keyatt
ri
butemaynotbefuncti
onall
ydependenton
anothernon-keyat
tr
ibut
e.
Pr
ocessf
or3NF
 Eli
minateal
ldependentatt
ri
butesint
ransi
ti
ver
elat
ionshi
p(s)f
rom eachoft
het
abl
es
thathaveatr
ansit
iverel
ati
onship.
 Cr
eat
enewt
abl
e(s)wi
thr
emoveddependency.
 Checknewt abl
e(s)aswellastabl
e(s)modif
iedtomakesurethateacht
abl
ehasa
det
erminantandt hatnot
ablecontai
nsinappropr
iat
edependenci
es.

Boyce-
CoddNor
malFor
m(BCNF)
Whenatabl
ehasmor ethanonecandi
dat
ekey,anomali
esmayresultevent
houghtherel
ati
on
i
sin3NF.Boyce-Coddnormalf
ormisaspeci
alcaseof3NF.Ar
elat
ionisinBCNFif
,andonlyif
,
ever
ydet
erminantisacandi
dat
ekey.

E4.
3Gi vent
heStudent_Gr
ade_Repor
ttabl
ebel
owf
rom aUni
ver
sit
ydat
abase,
usei
tto
answerthequest
ionsbel
ow.
St
uName Maj
or CosNo CosName AdvNo AdvName AdvHome Gr
ade
St
uNo
1121 Emeka Mat
hs Mt
h101 Al
gebr
a 50 Dr
.Sam Onui
yi A
Mt
h102 Cal
cul
us C
Mt
h103 Quadr
ati A
c
1245 Ber
nice Mat
hs Mt
h202 Equat
ion 71 Mr
.Ugwu Mbanef
o B
Mt
h101 Al
gebr
a B
Mt
h211 Li
near A
Mt
h103 Quadr
ati D
c
1264 Mar
k Mat
hs Mt
h202 Equat
ion 82 Pr
ofSmi
th Bar
racks A
Mt
h211 Li
near A
Mt
h102 Cal
cul
us B

E4.
3.1Nor
mal
izet
het
abl
eto1NF

St
uNo St
uName Maj
or CosNo CosName AdvNo Tut
orName advHome Gr
ade
1121 Emeka Mat
h Mt
h101 Al
gebr
a 50 Dr
.Sam Onui
yi A
s
1121 Emeka Mat
h Mt
h102 Cal
cul
us 50 Dr
.Sam Onui
yi C
s
1121 Emeka Mat
h Mt
h103 Quadr
ati
c 50 Dr
.Sam Onui
yi A
s
1245 Ber
nice Mat
h Mt
h202 Equat
ion 71 Mr
.Ugwu Mbanef
o B
s
1245 Ber
nice Mat
h Mt
h101 Al
gebr
a 71 Mr
.Ugwu Mbanef
o B
s
1245 Ber
nice Mat
h Mt
h211 Li
near 71 Mr
.Ugwu Mbanef
o A
s
1245 Ber
nice Mat
h Mt
h103 Quadr
ati
c 71 Mr
.Ugwu Mbanef
o D
s
1264 Mar
k Mat
h Mt
h202 Equat
ion 82 Pr
of Bar
racks A
s Smit
h
1264 Mar
k Mat
h Mt
h211 Li
near 82 Pr
of Bar
racks A
s Smit
h
1264 Mar
k Mat
h Mt
h102 Cal
cul
us 82 Pr
of Bar
racks B
s Smit
h

E4.
3.2a Nor
mal
izet
het
abl
eto2NF
St
udent
St
uNo St
uName maj
or advNo advName advHome
1121 Emeka Mat
hs 50 Dr
.Sam Onui
yi
1245 Ber
nice Mat
hs 71 Mr
.Ugwu Mbanef
o
1264 Mar
k Mat
hs 82 Pr
ofSmi
th Bar
racks
Cour
se Gr
ade
cosNo cosName St
uNo cosNo gr
ade
Mt
h101 Al
gebr
a 1121 Mt
h101 A
Mt
h102 Cal
cul
us 1121 Mt
h102 C
Mt
h103 Quadr
ati
c 1121 Mt
h103 A
Mt
h202 Equat
ion 1245 Mt
h202 B
Mt
h211 Li
near 1245 Mt
h101 B
1245 Mt
h211 A
1245 Mt
h103 D
1264 Mt
h202 A
1264 Mt
h211 A
1264 Mt
h102 B

E4.
3.2b I
dent
if
ythepr
imar
ykeysi
nthenor
mal
ized2NFt
abl
e
St
udentTabl
e:st
uNo(
PK)

Cour
seTabl
e:cour
seNoPK)

Gr
adeTabl
e:st
uNo(
PK)
cour
seNo(
PK)

E4.
3.3a Nor
mal
izet
het
abl
eto3NF

St
udent Advi
sor
St
uNo St
uNam maj
or advNo advNo advName advHome
e 50 Dr
.Sam Onui
yi
1121 Emeka Mat
hs 50 71 Mr
.Ugwu Mbanef
o
1245 Ber
nice Mat
hs 71 82 Pr
ofSmi
th Bar
racks
1264 Mar
k Mat
hs 82
Cour
se Gr
ade
cosNo cosName St
uNo cosNo gr
ade
Mt
h101 Al
gebr
a 1121 Mt
h101 A
Mt
h102 Cal
cul
us 1121 Mt
h102 C
Mt
h103 Quadr
ati
c 1121 Mt
h103 A
Mt
h202 Equat
ion 1245 Mt
h202 B
Mt
h211 Li
near 1245 Mt
h101 B
1245 Mt
h211 A
1245 Mt
h103 D
1264 Mt
h202 A
1264 Mt
h211 A
1264 Mt
h102 B

E4.
3.3b I
dent
if
ythepr
imar
ykeysi
ntheNor
mal
ized3NFt
abl
e

St
udentTabl
e:st
uNo(
PK) advi
sorTabl
e:advi
sor
No(
PK)
Cour
seTabl
e:cosNoPK)
Gr
adeTabl
e:st
uNo(
PK)&cosNo(
PK)

5 RELATI
ONALDATABASE
Ar el
ationaldatabase(RD)i
sonewhosesymbol
sareor
gani
zedint
oacoll
ect
ionofr
elat
ions.
TheFi gurebelowi sanexampl
es,
whichi
ssimil
art
owhatwearealr
eadyf
amili
arwi
th;a
tabularpresentati
on.
Thecomponent
sofadat
abaset
abl
ear
e:
a)At
tr
ibut
e b)Domai
n c)Tupl
e d)Degr
ee e)Car
dinal
it
y f
)Pr
imar
yKey
g)For
eignKey

Mostofthepr
oblemsfacedatthet
imeofi
mplementati
onofanysyst em usual
lyar
easaresult
ofapoordatabasedesign.Inmanycasesithappenst hatsyst
em hast obecont
inuously
modif
iedinmult
ipl
erespect
sduetochangi
ngrequirementsofusers.Itisver
yimpor
tantthat
pr
operpl
anni
ngi
scar
ri
edoutbef
orest
art
ing.
Thegoalofar elati
onaldat
abasedesignist ogenerat
easetofr el
ati
onschemathatall
owsus
tostor
einformat i
onwi t
houtunnecessaryredundancyandal sotoret
ri
eveinf
ormati
oneasily.
Andnormalizat
ioni susual
lycarr
yingouttoensurethatvar
iousanomali
esandinconsi
stenci
es
arenoti
ntr
oducedi nt
othedatabase.

E5.
1Def
inet
hef
oll
owi
ngRDt
ermi
nol
ogi
es:Rel
ati
on,
Rel
ati
onalAl
gebr
a,Compar
ison
oper
ator
s

Rel
ati
oni
saf
ormalt
ermi
nmat
hemat
ics;i
tist
hel
ogi
calf
oundat
ionofmat
hemat
ics.I
tappeal
s
t
ot henoti
onofr
elat
ionshi
psbet
weent
hings.AndRDt
heor
yisbui
ltar
oundt
heconceptofa
r
elati
on.
Relat
ionalal
gebra:a setofmat
hemat
icaloper
ator
sthatoper
ate on r
elat
ions and yi
eld
rel
ati
onsasresul
ts.
Compari
sonoperat
ors,
all
owingconsi
stencyrul
estobeexpr
essedasconst
rai
nts(
commonl
y
cal
ledi
ntegr
it
yconst
rai
nts)ont
hevari
ablesconst
it
uti
ngt
hedatabase.

DBMSandRDBMS
Mostoft heprobl emsf acedatt hetimeofimpl ementati
onofanysyst em areout comeofapoor
databasedesi gn.I nmanycasesi thappenst hatsystem hast obecont i
nuouslymodi fi
edi n
responset ochangi ngr equirementsofuser s.Itisthereforeimportantthatapr operplanning
hast obedone.
Ar el
ati
oni nar elati
onaldat abaseisbasedonar elati
onalschema,whi chconsistsofa
numberofat t
ributes.Ther efore,arelati
onaldatabaseismadeupofanumberofr elat
ionsand
correspondingr el
ationaldat abaseschema.
Thegoalofar elati
onaldat abasedesigni stogener ateasetofr el
ationschemast hat
enableseasyst orageandr et
r i
evalofinf
ormationandwi thoutunnecessaryr edundancy

E5.
2Whatar
ethef
eat
uresofRDBMS?Gi
vet
hreeexampl
es.

 RDBMSst
andsf
orRel
ati
onalDat
abaseManagementSyst
em.
 I
nRDBMS,
dat
aisst
ruct
uredi
ndat
abaset
abl
es,
fiel
dsandr
ecor
ds.
 EachRDBMSt
abl
econsi
stsofr
ows;r
owconsi
stsofoneormor
eat
tr
ibut
es(
fi
elds)
.
 RDBMSstoret
hedat
aint
ocol
lect
ionoft
abl
es,
whi
chmi
ghtber
elat
edbycommonf
iel
ds
(col
umns)
.
 RDBMSal
sopr
ovi
der
elat
ionaloper
ator
stomani
pul
atet
hedat
ast
oredi
ntabl
es.
 MostRDBMSuseSQLasdat
abasequer
ylanguage.
 Eacht
abl
econt
ainsr
ecor
dsofapar
ti
cul
art
ype.
 Eachr
ecor
dtypedef
inesaf
ixednumberoff
iel
ds,
orat
tr
ibut
es.

Exampl
es:Themostpopul
arRDBMSar
e:MSSQLSer
ver
,DB2,
Oracl
eandMySQL.

E5.
3 WhatDoesaRDBMSDo?
RDBMSar
eusedt
o:
 cr
eat
eanddest
royvar
iabl
esi
nthedat
abase
 pr
ovi
dei
ntegr
it
yrul const
es( rai
nts)
 pr deaut
ovi hor
isat
ions:whoi
sal
lowedt
odowhat
,towhat
 updat
evar
iabl
es;honour
ingconst
rai
ntsandaut
hor
isat
ions
 pr
ovi
deout
put
/resul
tsofquer
ies

E5.
4 Uset
heBookt
abl
esbel
owt
oexpl
ainf
oll
owi
ngt
ermi
nol
ogi
esoft
heRel
ati
onalDat
a
Model
a)Degr
ee b)Tupl
e c)Car
dinal
it
y d)At
tr
ibut
e e)Pr
imar
yKey
f
)For
eignKey g)Rel
ati
onScheme

Tabl
e:Book
BookI
D Ti
tl
e Aut
hor Publ
isher Cat
egor
y Pr
ice Br
anchI
D
C101 At
oZC++ LeeChung EvansLTD I
T 200 10
Fung
C102 I
ntr
oduct
ion Davi
dMaduka G.
Boar
dDee Busi
ness 250 10
ToComputi
ng
C103 I
ntr
oto Al
iFer
dinar
n OkekeF. Physi
cs 230 12
Comput
erPhy
C104 Al
gebra JohnThomas EvansLTD Mat
hemat
ic 180 11
Mathemat
ic
C106 Basi
cSt
at AhmadFr
ed EvansLTD St
ati
sti
cs 200 11

a)Degr
ee=7
b)Tupl
e=C101,
AToZC++,
LeeChungFung,
EvansLTD,
IT,
200,
10
=C102,
Int
roduct
ionToComput
ing,
Davi
dMaduka,
G.Boar
dDee,
Busi
ness,
250,
10
=C103,
Int
roduct
ionToPhy,
AliFer
dinar
n,OkekeF.
,Physi
cs,
230,
12
=C104,
Algebr
aMat
hemat
ic,
JohnThomas,
EvansLTD,
Mat
hemat
ic,
180,
11
=C106,
Basi
cSt
at,
AhmadFr
ed,
EvansLTD,
Stat
ist
ics,
200,
11
c)Car
dinal
it
y=5
d)At
tr
ibut
e=BookI
D,Ti
tl
e,Aut
hor
,Publ
isher
,Cat
egor
y,Pr
ice,
BranchI
D
e)Pr
imar
yKey=BookI
D
f
)For
eignKey=Br
anchI
D
g)Rel
ati
onScheme=BOOK(
BookI
D,Ti
tl
e,Aut
hor
,Publ
isher
,Cat
egor
y,Pr
ice,
BranchI
D);

Dat
aTypes
Whencreat
ingtabl
es,
youarer
equiredtospeci
fyt
hedatatypeforeachatt
ri
bute(col
umn),you
havet
ogiveeachtabl
eaname(e.g.passenger
,empl
oyee,
customer).Youalsohavetospecif
y
whatt
ypeandsizeofdat
athet
abl
ewi llhol
d.
Dat
at ypesvar ybetweenimpl ement
ati
onsbecauseofthewayeachdatabaseserverstor
es
dat
a.Fori nstance,Oracl
eusessel ect
eddatatypes,wher
easSybaseandMi cr
osoft'
sSQL
Ser
verhavet hei
rowndat atypes.

E5.
5St
ateanduseonesent
encet
oexpl
ainanyf
ivedat
atypesoft
heRDBMSusedi
nthe
pr
act
ical
.

Char
act
erSt
ri
ngs
 charstor
esf i
xed-l
engt
hcharact
erst
ri
ngs,suchasSTATEabbr
evi
ati
ons,whenyou
knowthatthecol
umnwi l
lal
waysbet
wocharact
ers.
 varcharstor
esvari
abl
e-l
engt
hchar
acterst
ri
ngs,suchasanindi
vidual
'
sname,where
the exactlengt
h ofa name i
s notspecif
ied,f
orexampl
e,AL RAY to WILLI
AM
STEPHENSON.
 textst
oresstr
ingswit
hnear
lyunl
imi
tedsi
ze,suchasar
emar
kscol
umnordescr
ipt
ion
ofatypeofservi
ce.
Numer
ic
 i
ntst
oresi
nteger
sfr
om -
2,147,
483,
647t
o+2,
147,
483,
647.
 smal
li
ntst
oresi
nteger
sfr
om -
32,
768t
o32,
767.
 t
inyi
ntst
oresi
nteger
sfr
om 0t
o255.
 f
loatexpr
essesnumber
sasr
ealf
loat
ing-
poi
ntnumber
swi
thdat
apr
eci
sions.
 Deci
malsar
eal
lowedwi
tht
hesedat
atypes.Theval
uesr
angef
rom +2.
23E-
308t
o
+1.
79E308.
 r
ealexpr
essesr
ealnumber
swi
thdat
apr
eci
sionsf
rom +1.
18E-
38t
o+3.
40E38.
DATE
 dat
eti
meval
uesr
angef
rom Jan1,
1753t
oDec31,
9999.
 smal
ldat
eti
meval
uesr
angef
rom Jan1,
1900t
oJun6,
2079.
Money
 moneyst
oresval
uesupt
o+922,
337,
203,
685,
477.
5808.
 smal
lmoneyst
oresval
uesupt
o+214,
748.
3647.
Bi
nar
ySt
ri
ngs
 bi
nar
yst
oresf
ixed-
lengt
hbi
nar
yst
ri
ngs.
 var
binar
yst
oresvar
iabl
e-l
engt
hbi
nar
yst
ri
ngs.
 i
magest
oresver
ylar
gebi
nar
yst
ri
ngs,
forexampl
e,phot
ogr
aphsandot
heri
mages.
bi
t:ALogi
calDat
aType
Thedatatypebitisoft
enusedtoflagcer
tai
nr owsofdat awit
hinatabl
e.Thevalue
st
oredwit
hinacolumnwhosedatatypei
sbiti
sei t
hera1or0.Forexample,t
heval
ue1
maysigni
fythecondi
ti
ontr
ue,wher
eas0denotesafalsecondi
ti
on.

E5.
6 Li
stt
hebasi
cst
epsi
npl
anni
ngadat
abase:
The f
oll
owing ar
ethe basi
c st
eps i
n pl
anni
ng t
he dat
abase,r
egar
dless ofi
ts si
ze and
compl
exit
y:
 Gat
herinf
ormati
on,Ident
if
yandmodeltheobj
ects,
Ident
if
ytypesofi
nfor
mat
ionf
oreach
obj
ectandIdent
if
ytherel
ati
onshi
psbet
weenobjects.

E5.
7 St
atet
hemaj
orconsi
der
ati
onswhendesi
gni
ngadat
abase
Whendesi
gni
ngadat
abase,
consi
der
:
 Thepur
poseoft
hedat
abase;cr
eat
eadat
abasepl
ant
ofi
tyourpur
pose.
 Howt
opr
eventmi
stakesi
nthedat
abasedesi
gnt
hroughnor
mal
izat
ion.
 Pr
otect
ion(
ordat
aint
egr
it
y).
 Secur
it
yrequi
rement
soft
hedat
abaseanduserper
missi
ons.
 Per
for
mance needs oft
he appli
cati
on;achi
evi
ng a bal
ance bet
ween t
he si
ze oft
he
dat
abaseandt
hehardwar
econfigurat
ioni
simpor
tantf
orper
for
mance.
 Mai
ntenance.
 Est
imat
ingt
hesi
zeofadat
abase.
6 USI
NGARELATI
ONALDATABASEMANAGENTSYSTEM

Requi
rement
s:
AComput erI
nst
all
edwit
haRelati
onalManagementDat
abaseSyst
em (
RDBMS)
;Exampl
e,MS-
AccessDB,MySQL,MongoDB,
etc.

 Thestudent
sshoul
dbet
akent
hroughpr
act
icall
essonsont
hei
nst
all
ati
onanduseofa
chosenRDBMS.
 For100-
levelst
udent
stheMSAccessDBshoul
dbei
ntr
oducedf
ir
st.
 The100-l
evelst
udent
sshouldbeguidedonusi
ngtheDesi
gnViewofMSAccesst
o
cr
eateandmanageDatabaseandit
scomponents;t
abl
es,f
orms,r
epor
ts,
etc

Obj
ect
ives:
Thef
oll
owi
ngar
etheobj
ect
ivesoft
hisl
abor
ator
ysessi
on:
 Teacht
hei
nst
all
ati
onofRDBMS
 TeachtheuseRDBMSt
ool
sandsubl
anguaget
ocr
eat
est
ruct
ures,
managedat
aand
gener
aterepor
ts

Lear
ningOut
come:
Att
heendoft
hissessi
oni
nthel
abor
ator
y,t
hest
udentshoul
dbeabl
eto:
 I
nst
allaRDBMS
 I
dent
if
ythebasi
ccont
ent
sandusesofDat
abasemanagement
 Appl
ytheRDBMSt
ool
stocr
eat
eandmanagest
ruct
ures,
andgener
ater
epor
tsf
rom dat
a
i
nadatabase
 Uset
hevar
ioust
ool
sandcommandofSQLst
atedbel
owt
o:
 Descr
ibe(
def
ine)
,modi
fyandaccessdat
athedat
abase,
tabl
esandvi
ews
 Per
for
m basi
cdat
amanagementchor
es(
add,
del
eteandmodi
fy)oft
hest
ruct
ures.
 Tr
ansf
ormr
awdat
aint
ousef
uli
nfor
mat
ion
 Enabl
etheusert
ocr
eat
eanddi
scar
ddat
abasesandt
abl
es,
 Cr
eat
evi
ewsandst
orepr
ocedur
es
 Setper
missi
onsont
abl
es,
procedur
es,
andvi
ews.

I
ntr
oduct
iont
oMS-
AccessDBMS
MSAccessuses“ objects"tohelptheusertocreatestr
ucturewhi chhold(store)andor gani
ze
data,
aswellaspreparespeciall
ydesignedreport
sthattr
ansform dat atoi
nformation.TheMS-
Accessi
susedcreatedat abasesanditscomponents;Tables,Queries,For
ms, Reports,Macros,
andModules.Together,theseobject
sal l
ow theuserofthedat abaset oenter,st
ore,analyze,
andcompil
edata.
Bel
owi
sasummar
yoft
hemaj
orobj
ect
sinanAccessdat
abase

Tableobjectiscreatedtostor
e(hold)data.Whentablei
sbei
ngcr
eat
ed,MS-Accessrequi
res
thatyoudefine(specif
y)thefi
eldswhichi salsoknownascol
umnheadi
ngs,dat
atypesand
otherpr
opertiesofdatatobestoredinthetabl
e,
Query-obj
ectpr
ovidesacust
om viewofdat
afr
om oneormoretabl
es.Quer
iesar
eawayof
sear
chi
ngforandcompil
ingdataf
rom oneormoret
abl
esint
orequir
edinf
ormati
on.
Formi sanobjectinadatabasedesignedprimari
lyf
ordatainputoroutput
,orf
orcontr
olof
appl
icati
on executi
on.You use for
ms t o cust
omize t
he present
ati
on ofdat
at hatyour
appl
icati
onextract
squer
iesappl
iedont abl
es.
Repor
tis an object i
n dat
abases desi
gned f
or f
ormat
ti
ng,cal
cul
ati
ng,pr
int
ing,and
summari
zingsel
ect
eddata.
Macr oisastruct
ureddefi
nit
ionofoneormoreact
ionsthatyouwantAccesstoperfor
mi n
responsetoadefi
nedevent.AnAccessMacroisascri
ptfordoingsomejob.Forexample,t
o
createabutt
onwhi chopensareport
,youcoul
duseamacr owhi chwi
llf
ir
eOpenReportacti
on.
Modul
e
Moduleisanobjectindesktopdat
abasescont
aini
ngcust
om procedur
esthatyoucode(
wri
te)
usingahighl
evellanguage.Modul
esprovi
deamor edi
scr
etefl
owofact i
onsandall
owyout o
tr
aperror
s.

Acti
vit
y:6.
1 UseRDBMStocr
eat
ethecust
omert
abl
eandFor
m,andusedt
heFor
mtoent
er
thedataasshowni
nthet
abl
ebel
ow.
TABLE:Cust
omer
I
D NAME AGE ADDRESS EARNI
NG
1 Adaobi 25 I
bagwa 30000
2 Mer
cy 27 Or
ba 35000
3 Kaosi
so 26 Enugu- 30000
Ezi
ke
4 Mat
thew 31 Ngur
u 32000
5 Hyaci
nth 31 I
mil
iki
-Enu 40000
6 Nneka 30 Opi 36000
7 Nchet
a 32 Ukana 32000

E6.1 Usethecust
omert
abl
e,t
owr
it
etheQuer
yst
atement
sandshowr
esul
tsoft
he
fol
lowi
ng:
a.Theear
ningsofper
sonwhoseagei
sabove25andear
ning25000orabove.
b. I
nser
tanewcust
omer
:Obi
nna,
aged28,
li
vingi
nNsukkaandear
nins34000.
c. Changet
headdr
essofNnekat
oOvokoandshowt
heout
put
.
d. Del
eteanycust
omer
swhoseagei
s31

a.Tofindt
heear
ningsofper
sonwhoseagei
sabove25andear
ning25000and
above.

SQL>SELECT*FROM CUSTOMERSWHEREAGE<=26ANDEARNI
NG<=30000;

Out
put
:
I
D NAME AGE ADDRESS EARNI
NG
1 Adaobi 25 I
bagwa 30000
3 Kaosi
so 26 Enugu-
Ezi
ke 30000
2r
owssel
ect
ed.

b. Toi
nser
tanewcust
omerObi
nna,
aged28,
li
vingi
nNsukkaandear
nins34000.

SQL>I
NSERTI
NTOCust
omert
abl
eVALUE(
8,“
Obi
nna”
,28,
“Nsukka”
,34000)
Out
put
:
I
D NAME AGE ADDRESS EARNI
NG
1 Adaobi 25 I
bagwa 30000
2 Mer
cy 27 Or
ba 35000
3 Kaosi
so 26 Enugu- 30000
Ezi
ke
4 Mat
thew 31 Ngur
u 32000
5 Hyaci
nth 31 I
mil
iki
-Enu 40000
6 Nneka 30 Opi 36000
7 Nchet
a 32 Ukana 32000
8 Obi
nna 28 Nsukka 34000
8r
owssel
ect
ed

c. Tochanget
headdr
essofNnekat
oOvokoandshowt
heout
put
.

SQL>UPDATECUSTOMERSSETADDRESS=“
Ovoko”WHERENAME=“
Nneka”
;

Out
put
:
I
D NAME AGE ADDRESS EARNI
NG
6 Nneka 30 Ovoko 36000
1r
owsel
ect
ed.

d. Todel
eteanycust
omer
swhoseagei
s31

SQL>DELETEFROM CUSTOMERWHEREAGE=31;
Out
put
:
I
D NAME AGE ADDRESS EARNI
NG
1 Adaobi 25 I
bagwa 30000
2 Mer
cy 27 Or
ba 35000
3 Kaosi
so 26 Enugu- 30000
Ezi
ke
6 Nneka 30 Ovoko 36000
7 Nchet
a 32 Ukana 32000
8 Obi
nna 28 Nsukka 34000
6r
owssel
ect
ed.

6.
1 Dat
aCont
rolLanguage(
DCL)

TheDCLcommandsareusedtocontr
olaccesstodat
abaset
abl
es,
andhencepr
ovi
desecur
it
y
measur
e.I
tpr
ovi
descert
ainsyst
em pri
vil
egestouser
s.
Apri
vil
egei
sar ightt
oexecuteSQLstatementoraccessanotherdat
abaseobject
s,and
suchr
ight
sareall
ocated.Thepr
ivi
legecommandsar eassignedusingtheGrantandRevoke
commands.Thepri
vil
egesthatmaybegr ant
edorrevokedareSelect,
Inser
t,Del
eteandUpdate.

E6.
2 Cr
eat
eandUset
hepr
oductt
abl
e,t
owr
it
etheSQLst
atement
sandshowr
esul
tsoft
hef
oll
owi
ng:

a.Gr
antal
lpr
ivi
legest
oUser
1
b.Gr
antSel
ectandI
nser
ttoUser
1
c.Revokeal
lpr
ivi
legest
oUser
1
d.RevokeSel
ectandI
nser
tpr
ivi
legest
oUser
1
e.Inser
t4newpr
oduct
sgi
venbel
owusi
ngt
hecommi
t,savepoi
ntandr
oll
back
commands.
Thenewpr
oduct
sar
e
106 DVDdr
ive 900
107 CDdr
ive 800
108 Pr
int
er 2600
109 Ref
il
lcar
tri
dge 350

ThePr
oductt
abl
e
PRO_
ID PRO_
NAME PRO_
PRI
CE
101 Mot
herBoar
d 3200
102 KeyBoar
d 450
103 ZI
Pdr
ive 250
104 Speaker 550
105 Moni
tor 5000

a.Thequer
ytogr
antal
lpr
ivi
legest
oUser
1
SQL>GRANTALLONPRODUCTTABLETOUser
1;

b.Thequer
ytogr
antSel
ectandI
nser
tpr
ivi
legest
oUser
1
SQL>GRANTSELECT,
INSERTONPRODUCTTABLETOUser
1;

c.Thequer
ytor
evokeal
lpr
ivi
legesofUser
1
SQL>REVOKEALLONPRODUCTTABLEFROM User
1;
d.Thequer
ytor
evokeSel
ectandI
nser
tpr
ivi
legesofUser
1
SQL>REVOKESELECT,
INSERTONPRODUCTTABLEFROM User
1;
e.Thequer
ytoI
nser
t4newpr
oduct
susi
ngt
hecommi
t,savepoi
ntandr
oll
backcommands.

SQL>I
NSERTI
NTOPRODUCTTABLEVALUES(
106,
'DVDdr
ive'
,900)
;
SQL>SAVEPOI
NTS1;
SQL>I
NSERTI
NTOPRODUCTTABLEVALUES(
107,
'CDdr
ive'
,800)
;
SQL>SAVEPOI
NTS2;
SQL>I
NSERTI
NTOPRODUCTTABLEVALUES(
107,
'Pr
int
er'
,2600)
;
SQL>SAVEPOI
NTS3;
SQL>I
NSERTI
NTOPRODUCTTABLEVALUES(
107,
'Ref
il
lcar
tri
dge'
,350)
;
SQL>COMMI
T;
SQL>SELECT*FROM PRODUCTTABLE

Out
put
:
PRO_
ID PRO_
NAME PRO_
PRI
CE
101 Mot
herBoar
d 3200
102 KeyBoar
d 450
103 ZI
Pdr
ive 250
104 Speaker 550
105 Moni
tor 5000
106 DVDdr
ive 900
107 CDdr
ive 800
108 Pr
int
er 2600
109 Ref
il
lcar
tri
dge 350
9r
owssel
ect
ed

Act
ivi
ty6.
2:
PeaceMassTr ansit-Isi
nbusinesswithsever
albusesconnect
ingdif
fer
entpl
acesi
nNiger
ia.
I
tsmainoff
iceislocatedi
nEnugu.Thecompanywant stocomputer
izeit
soper
ati
onsint
he
f
oll
owingareas:Reservat
ions,
Ticket
ingandCancell
ati
ons

Reser
vat
ions:
Reservat
ionsaredir
ect
lyhandeledbybooki
ngof f
ice.Reservati
onscanbemade10daysi n
advanceineit
hercashorcredi
t.Incaset
heticketisnotavail
able,
awaitl
ist
edt
icketi
sissued
tothecustomer.Thi
sti
cketisconfi
rmedagai
nstt hecancell
ati
on.
Cancel
lat
ionandmodi
fi
cat
ion:
Cancel
lat
ionsar
eal
sodi
rect
lyhandedatt
hebooki
ngof
fi
ce.Cancel
lat
ionchar
geswi
llbe
char
ged.
Wai
tli
stedt
icket
sthatdonotgetconf
ir
medar
eful
lyr
efunded.
E6.
3 Analyzethepr
oblem anddiagr
ammat
ical
lyshowt
henecessar
yent
it
iesandper
sist
ent
dat
aforeachenti
tyi
nthedatabases.
TheFol
lowi
ngar
etheent
it
ies:
1.
Bus
2.Reser
vat
ion
3.Ti
cket
4.Passenger
5.Cancel
lat
ion

Theat
tri
but
esi
ntheEnt
it
ies:
Bus Reser
vat
ion

Dest
inat
i
Sour
c on
Bus Cont
act
N NO-of
-
e o Seats
Type Jour
ney
Bus- Bus Date
Addr
es
No Reser
vat
io s
PRNNO n
Bus-
No

Passenger Ti
cket

Cont
act
N Dep-
Time
Sour
ce
Sex o
Ti
cket
N Jour
ney
Date
o Sex
PNR- Ti
cket
Passenge Age
No r
Age
Bus-
Ti
cket Dest
inat
i No
Nam NO on
e

Cancel
lat
ion

Cont
act
N
Jour
ney
Date
o
Seat
No
PNR- Cancel
lat
ion
No
Act
ivi
ty6.
3:Adat
abasei
sbei
ngconst
ruct
edf
orst
ori
ngsal
esi
nfor
mat
ionsyst
em.
 Aproductcanbedescr
ibedwi
thauni
quepr
oductnumber
,pr
oductname,
sel
li
ngpr
ice,
manufact
urername.
 Thepr oductcansal
et oaparti
cul
arcli
entandeachcli
enthasi
tsownuniquecl
ient
number ,cl
ientname,cl
ientaddr
esses,ci
ty,pi
ncode,st
ateandtot
albal
ancetobe
requi
redtopaid.
 Eachcl
ientpl
acesor
dert
obuypr
oductf
rom t
hesal
esman.
 Theorder,haveuni
quesal
esordernumber
,sal
esorderdat
e,cl
ientnumber,sal
esman
number(unique)
,bi
ll
edwholepaymentbyt
hepart
yornotandit
sdeliver
ydate.
 Thesalesmanhavename,addr
esses,cit
y,pi
ncode,st
ate,sal
aryoft
hesal
esman,
del
iver
ydate,
tot
alquant
it
yor
der
ed,productr
ate.

E6.
4 Wr
it
etheSQLcommandst
oCr
eat
etheTabl
es:
-

Creat
etablepr
oduct(
Prod_
IDvarchar(
10)pri
marykey,Prod_Namevarchar
(20)
,Manu_
Name
char(
20),
Prod_
Ratenumber(
9,4)
,sel
l_
pricenumber
(5,
2),Prod_Descvar
char
(25)
);

Creat
etablecli
ent(Cl
i_
IDvarchar(
10)primar
ykey,
Cli
_Namechar
(20)
,addr
essvar
char
(15)
,ci
ty
char(
15),
Pin_No(8)
,st
atechar(15)
,bal
_duenumber
(9,
4))
;

Cr
eatetabl
esalesman(sal
_idvarchar(
10)primar
ykey,sal
_namechar
(20)
,addr
essvar
char
(15)
,
ci
tychar(
15),
Pin_No(
8),st
atechar(15)
,sal
arynumber(
9,4)
);
Cr
eat
etabl
esal
es_
Det(
sal
_or
d_Novar
char
(10)pr
imar
ykey,
sal
_or
d_Datdat
e,Cl
i_
ID
var
char
(10)r
efer
encescl
ient
(Cl
i_
ID)
,sal
_i
dvar
char
(10)r
efer
encessal
(sal
_i
d),
Bil
l_
PayBychar
(5)
,DEl_
Dat
edate,
Prod_
Rat
enumber
(9,
4),
TOT_
Qty_
Ordnumber
(8)
,
cancel
_dat
edat
edefaul
tNULL)
;

E6.
4aWr
it
etheSQLcommandst
oSeeDef
ini
ti
onofanyt
wooft
heTabl
es:
-

SQL>Descpr
oduct
; SQL>Descpr
oduct
;
Name Nul
l? Type Name Nul
l? Type
-
---
---
---
---
---
---
---
---
---
---
---
---
---
---
---
--- --
-----
---
---
---
---
---
---
---
---
---
---
---
---
---
--
-
---
---
---
- ----
-
PROD_
ID NOTNULL VARCHAR2(
10) PROD_
ID NOTNULLVARCHAR2(
10)
PROD_
NAME VARCHAR2(
20) PROD_
NAME VARCHAR2(
20)
MANU_
NAME CHAR(
20) MANU_
NAME CHAR(
20)
PROD_
RATE NUMBER(
9,4) PROD_
RATE NUMBER(
9,4)
SELL_
PRI
CE NUMBER(
9,4) SELL_
PRI
CE NUMBER(
9,4)
PROD_
DESC VARCHAR2(
25) PROD_
DESC VARCHAR2(
25)

SQL>Desccl
ient
; SQL>Descsal
esman;
Name Nul
l? Type Name Nul
l? Type
-
---
---
---
---
---
---
---
---
---
---
---
---
---
---
---
--- --
-----
---
---
---
---
---
---
---
---
---
---
---
---
---
--
-
--- ----
-
CLI
_ID NOTNULL VARCHAR2(
10) SALESMANU_
NAME CHAR(
20)
CLI
_NAME CHAR(
20) ADDRESS VARCHAR2(
15)
ADDRESS VARCHAR2(
15) CI
TY CHAR(
15)
CI
TY CHAR(
15) PI
N NUMBER(
8)
PI
N NUMBER(
8) STATE CHAR(
15)
STATE CHAR(
15) SALARY NUMBER(
9,4)
BAL_
DUE NUMBER(
9,4)

E6.
4aWr
it
etheSQLcommandst
oSeeDef
ini
ti
onofanyt
wooft
heTabl
es:
-
Exampl
e:
SQL>Descsal
es_
Det
;
Name Nul
l? Type
-
---
---
---
---
---
---
---
---
---
---
---
---
---
---
---
----
---
---
---
---
SAL_
ORD_
NO NOTNULL VARCHAR2(
10)
SAL_
ORD_
DAT DATE
CLI
_ID VARCHAR2(
10)
SAL_
ID VARCHAR2(
10)
BI
LL_
PAYBY CHAR(
5)
DEL_
DATE DATE
PROD_
RATE NUMBER(
9,4)
TOT_
QTY_
ORD NUMBER(
8)
CANCEL_
DATE DATE

E6.
4bWr
it
etheSQLcommandst
oInser
t10val
uesi
ntoeachTabl
es:

SQLCommandt
oInser
tval
uesi
nthePr
oduct
I
nser
tint
opr
oductval
ues(
‘p001’
,
’l
ux_
soap’
,
’Lux_
Coy’
,
’15.
67’
,
’20.
43’
,
’soap’
);
I
nser
tint
opr
oductval
ues(
‘p002’
,
’copy’
,
’ti
mes_
copy_
org’
,
’14.
80’
,
’16.
40’
,
’copy
I
nser
tint
opr
oductval
ues(
‘p003’
,
biscui
t’
,’
mar
igol
d_or
g’,

2218.
80’
,
’2220.
40’
,
’bui
ski
t’
);
I
nser
tint
opr
oductval
ues(
‘p004’
,
’mi
tsubi
si_
pen’
,
’pen_
Coy’
,
’2015.
67’
,
’2120.
43’
,
’pen’
);
I
nser
tint
opr
oductval
ues(
‘p005’
,
’l
ear
n_books’
,
’book_
wor
ld’
,
’5104.
80’
,
’5116.
40’
,
’book’
);
I
nser
tint
opr
oductval
ues(
‘p006’
,
’I
nnoson_
steel
’,

Innoson_
org’
,
’5118.
80’
,
’5120.
40’
,
’I
nnoson’
);
I
nser
tint
opr
oductval
ues(
‘p007’
,
’seagat
ehdd’
,
’seaget
_wor
ld’
,
’5104.
80’
,
’5116.
40’
,
’HDD1034’
);
I
nser
tint
opr
oductval
ues(
‘p008’
,
’dvdwr
it
er’
,
’fr
ont
ec_
org’
,
’5118.
80’
,
’5120.
40’
,
’DVDRW’
);

I
nser
tint
ocl
ientval
ues(
‘cn01001’
,
’al
akr
oy’
,
’b.
d.par
a’,

amaka’
,
’799101’
,
’I
mo’
,
’390.
9’)
;
I
nser
tint
ocl
ientval
ues(
‘cl
01002’
,
’sumanr
oy’
,
’pukpar
a’,

agar
tha’
,
’799102’
,
’I
mo’
,
’2390.
9’)
;
I
nser
tint
ocl
ientval
ues(
‘cl
01004’
,
’pr
iyaada’
,
’chor
apar
a’,

kamal
pur
’,
’799301’
,
’I
mo’
,
’1390.
9’)
;
I
nser
tint
ocl
ientval
ues(
‘cl
01005’
,
’mi
tami
a’,
’kanupaul
’,

singur
’,
’799721’
,
’I
mo’
,
’190.
9’)
;
I
nser
tint
ocl
ientval
ues(
‘cl
01006’
,
’pul
akr
oy’
,
’bi
rci
ty’
,
’somt
oo’
,
’799141’
,
’enugu’
,
’110.
9’)
;
I
nser
tint
ocl
ientval
ues(
‘cl
01007’
,
’munniada’
,
’nnam’
,
’somt
oo’
,
’799152’
,
’enugu’
,
’190.
9’)
;
I
nser
tint
ocl
ientval
ues(
‘cl
01008’
,
’kusum r
oy’
,
’ci
ty_
dos’
,
’akunna’
,
’799141’
,
’enugu’
,
’110.
9’)
;
I
nser
tint
ocl
ientval
ues(
‘cl
01009’
,
’mi
naada’
,
’power
mike’
,
’akunna’
,
’799152’
,
’enugu’
,
’190.
9’)
;
I
nser
tint
ocl
ientval
ues(
‘cl
01003’
,
’monye’
,
’power
mike’
,
’akunna’
,
’799152’
,
’enugu’
,
’9990.
9’)
;
I
nser
tint
ocl
ientval
ues(
‘cl
01010’
,
’paur
imi
a’,
’power
mike’
,
’akunna’
,
’799152’
,
’enugu’
,
’2990.
9’)
;
I
nser
tint
ocl
ientval
ues(
‘cl
01011’
,
’manal
iada’
,
’sat
mil
e’,

akunna’
,
’799154’
,
’enugu’
,
’3990.
9’)
;

I
nser
tint
osal
esmanval
ues(
‘s001’
,
’Romanus’
,
’nnam’
,
’Akunna’
,
’79970’
,
’Enugu’
,
’8000’
);
I
nser
tint
osal
esmanval
ues(
‘s003’
,
’Smi
taada’
,
’ni
rj
uli
’,

itanagar
’,
’799701’
,
’Ar
unachal
’,

9000’
);
I
nser
tint
osal
esmanval
ues(
‘s004’
,
’Kabi
rbor
a’,

nnam’
,
’Akunna’
,
’799703’
,
’Enugu’
,
’8500’
);
I
nser
tint
osal
esmanval
ues(
‘s005’
,
’Nehasi
ngh’
,
’bor
bot
a’,

somt
oo’
,
’795970’
,
’enugu’
,
’9600’
);
I
nser
tint
osal
esmanval
ues(
‘s006’
,
’Pr
iyaagar
wal
’,

gandhir
oad’
,
’32di
str
ic’
,
’799750’
,
’del
hi’
,
’9900’
);
I
nser
tint
osal
esmanval
ues(
‘s007’
,
’AshokPaul
’,

fil
mci
ty’
,
’munnabar
i’,

799740’
,
’mumbai
’,

8900’
);

I
nser
tint
osal
es_
Detval
ues(
‘on01001’
,
’01-
aug-
08’
,
’cl
01001’
,
’s001’
,
’yes’
,
’20-
aug-
08’
,

2220.
40’
,
’50’
,
’’
);
I
nser
tint
osal
es_
Detval
ues(
‘on01002’
,
’12-
aug-
08’
,
’cl
01004’
,
’s001’
,’
yes’
,
’23-
aug-
08’
,

2220.
40’
,
’15’
.’
’)
;
I
nser
tint
osal
es_
Detval
ues(
‘on01003’
,
’12-
aug-
08’
,
’cl
01005’
,
’s003’
,’
yes’
,
’26-
aug-
08’
,

2220.
40’
,
’10’
,
’’
);
I
nser
tint
osal
es_
Detval
ues(
‘on01004’
,
’13-
aug-
08’
,
’cl
01004’
,
’s001’
,’
yes’
,
’20-
aug-
08’
,

2220.
40’
,
’15’
,
’’
);
I
nser
tint
osal
es_
Detval
ues(
‘on01005’
,
’14-
aug-
08’
,
’cl
01002’
,
’s002’
,’
no’
,
’30-
aug-
08’
,

2220.
40’
,
’52’
,’
28-
mar
ch-
08’
);
I
nser
tint
osal
es_
Detval
ues(
‘on01006’
,
’15-
aug-
08’
,
’cl
01001’
,
’s001’
,’
yes’
,
’31-
aug-
08’
,

2220.
40’
,
’53’
,
’’
);
I
nser
tint
osal
es_
Detval
ues(
‘on01007’
,
’16-
jan-
08’
,
’cl
01003’
,
’s004’
,’
yes’
,
’28-
aug-
08’
,

2220.
40’
,
’54’
,
’’
);
I
nser
tint
osal
es_
Detval
ues(
‘on01008’
,
’01-
feb-
08’
,
’cl
01004’
,
’s003’
,’
no’
,
’28-
aug-
08’
,

8220.
40’
,
’54’
,’
18-
mar
ch-
08’
);

E6.
4cWr
it
etheSQLcommandst
ogetval
uesf
rom eachoft
heTabl
es:
Commandt
ogetval
uesf
rom Tabl
es:
Sel
ect*f
rom cl
ient
;
Sel
ect*f
rom pr
oduct
;
Sel
ect*f
rom sal
esman;
Sel
ect*f
rom sal
es_
Det
;

E6.
5aRet
ri
evet
hel
istofnamesandt
heci
ti
esofal
lthecl
ient
s.
SQL>Sel
ectCl
i_
Name,
cit
yfr
om cl
ient
;
CLI
_NAME CI
TY
-
---
---
---
---
---
---
---
---
---
---
---
-
al
akr
oy amaka
sumanr
oy agar
tha
pr
iyaada kamal
pur
mi
tami
a si
ngur
pul
akr
oy somt
oo
munniada somt
oo
kusum r
oy akunna
mi
naada akunna
monyeakunna
paur
imi
a akunna
manal
iada akunna
11r
owssel
ect
ed.

E6.
5bFi
ndt
henamesofal
lcl
ient
shavi
ng‘
a’ast
hesecondl
ett
eri
nthei
rnames.
SQL>SELECTCl
i_
NameFROM cl
ientWHERECl
i_
NameLI
KE'
_a%'
;
CLI
_NAME
-
---
---
---
---
---
---
-
paur
imi
a
manal
iada
E6.
5cFi
ndt
hepr
oduct
swhosesel
li
ngpr
icei
sgr
eat
ert
han2000andl
esst
hanorequalt
o
5000
SQL>SELECT*FROM pr
oductWHEREsel
l_
pri
ce>2000AND(
sel
l_
pri
ce<5000OR
2sel
l_
pri
ce=5000)
;

PROD_
IDPROD_
NAME MANU_
NAMEPROD_
RATE SELL_
PRI
CEPRODUCT_
DESCRI
PTI
ON
-
---
---
----
---
---
---
---
---
---
---
---
---
---
---
---
----
---
---
---
---
---
---
---
---
---
---
---
---
---
--
-
---
-
p003 mar
ry_
biscui
t mar
igol
d_or
g 2218.
8 2220.
4 bui
ski
t
p004 mi
tsubi
si_
pen pen_
Coy 2015.
67 2120.
43 pen

E6.
5dAddanewcol
umnNew_
Pri
cei
ntot
hepr
oduct
_mast
ert
abl
e.(
Don’
tshowt
het
abl
e)
SQL>ALTERTABLEpr
oductADD(
new_
pri
cenumber
(9,
4))
;
Tabl
eal
ter
ed.

E6.
5eRenamet
hecol
umnPr
od_
Rat
eofSal
es_
Dett
onew_
Prod_
Rat
e.(
Don’
tshowt
het
abl
e)

SQL>ALTERt
abl
eSal
es_
DetRENAMEcol
umnPr
od_
Rat
etonew_
Prod_
Rat
e;
Tabl
eal
ter
ed.

E6.
5f Di
spl
ayt
heor
dernumberanddat
eonwhi
cht
hecl
ient
spl
acedt
hei
ror
der
.
SQL>SELECTsal
es_
order
_no,
sal
_or
d_DatFROM Sal
es_
Det
;

SALES_
ORDE SALES_
ORD
on01001 01-
AUG-
08
on01003 12-
AUG-
08
on01004 13-
AUG-
08
on01005 14-
AUG-
08
on01006 15-
AUG-
08
on01007 16-
JAN-
08
on01008 01-
FEB-
08
7r
owssel
ect
ed.

E6.
5gDel
eteal
lther
ecor
dshavi
ngdel
iver
ydat
ebef
ore25t
hAugust
,08.
SQL>DELETEFROM sal
es_
DetWHEREDEl
_Dat
e<'
25-
aug-
08'
;
2r
owsdel
eted.

E6.
5hChanget
hedel
iver
ydat
eofor
dernumberON01008t
o16-
08-
08
SQL>UPDATEsal
es_
DetSETDEl
_Dat
e='
16-
aug-
08'
WHEREsal
_or
d_No=
'
on01008'
;
1r
owupdat
ed.
E6.
5iLi
stt
henames,
cit
yandst
ateoft
hecl
ient
snoti
nthest
ateof‘
ENUGU’
SQL>SELECTCl
i_
Name,
ci
ty,
stat
eFROM cl
ientWHERENOTst
ate=‘
enugu’
;

CLI
_NAME CI
TY STATE
-
---
---
---
---
---
---
---
---
---
---
---
---
---
---
--
al
akr
oy amaka I
mo
sumanr
oy agar
tal
a I
mo
pr
iyaada kamal
pur I
mo
mi
tami
a si
ngur I
mo

E6.
5jLi
stofal
lor
der
scancel
ledi
nMar
ch

SQL>Sel
ect*f
rom sal
es_
Detwher
ecancel
_dat
eLI
KE'
%-MAR-
%';

S_
ORD_
N0 SAL_
Dat CLI
_ID SAL_
ID BI
LL_
PayByDel
_Dat
ePROD_
RATE TOT_
QtyCan_
Dat
e
-
---
---
------
-----
-----
---
-----
---
---
---
---
---
---
---
---
---
---
---
---
---
---
---
---
---
---
---
---
---
---
---
---
---
---
-
---
---
----
-----
-----
---
---
---
on01005 14-
AUG-
08 cl
01002 s002no 30-
AUG-
08 222 0.
4 52 28-
MAR-
08
on01008 01-
FEB-
08 cl
01004 s003no 16-
AUG-
08 822 0.
4 54
18-MAR-08

You might also like