DBS 2 Assignment
DBS 2 Assignment
nst
it
uteofSout
her
nPunj
abMul
tan
Depar
tmentofComput
erSci
ence
Assi
gnmentTopCov
er
Dat
e:19-
04-
2021
Assi
gnmentTool
used: Assi
gnment#2
FORSTUDENTUSE
Regi
str
ati
onNo. BSI
T-021R19-
10
Name ZeeshanManzoor
Cl
ass BS-
IT
Sect
ion A
Semest
er 5t
h
Sessi
on Mai
n-Spr
ing-
Regul
ar-
2019
Cour
seCode
Cour
seName Dat
abaseSy
stem
Cour
seCoor
dinat
or Ma’
am Mar
yam
Assi
gnmentNo 02
Descr
ipt
ion
St
udentSi
gnat
ure:
FORTEACHERUSE
Tot
alMar
ks:
Obt
ainedMar
ks:
TeacherSi
gnat
ure:
Quest
ionNo1
TheSQLdatamanipul
ati
onlanguage(DML)i
susedt
oquer
yandmodi f
y
dat
abasedat
a.I
nthischapt
er,wewill
descri
behowt
ousetheSELECT,
I
NSERT,UPDATE,andDELETESQLDMLcommandst at
ements,
defi
ned
bel
ow.
SELECT –t
oquer
ydat
aint
hedat
abase
I
NSERT–t
oinser
tdat
aint
oat
abl
e
UPDATE–t
oupdat
edat
ainat
abl
e
DELETE–t
odel
etedat
afr
om at
abl
e
I
ntheSQLDMLst
atement
:
Eachcl
ausei
nast
atementshoul
dbegi
nonanewl
i
ne.
Thebegi
nni
ngofeachcl
auseshoul
dli
neupwi
tht
hebegi
nni
ngofot
her
cl
auses.
I
faclausehasseveral
parts,
theyshouldappearonsepar
ateli
nesand
bei
ndentedunderthestar
toftheclausetoshowtherel
ati
onshi
p.
Uppercasel
ett
ersar
eusedt
orepr
esentr
eser
vedwor
ds.
Lowercasel
ett
ersar
eusedt
orepr
esentuser
-def
inedwor
ds.
SELECTSt
atement
TheSELECTst atement
,orcommand,al
lowstheusert
oextr
actdata
from t
ables,
basedonspecif
iccr
it
eri
a.I
tispr
ocessedaccor
dingt
othe
foll
owingsequence:
SELECTDI
STI
NCTi
tem(
s)
FROM t
abl
e(s)
WHEREpr
edi
cat
e
GROUPBYf
iel
d(s)
ORDERBYf
iel
ds
Wecanuset
heSELECTstat
ementt
ogener
ateanempl
oyeephonel
i
st
f
rom t
heEmpl
oyeest
abl
e
I
NSERTst
atement
TheINSERTst
atementaddsrowstoat
able.Inaddi
ti
on,I
NSERT
speci
fi
esthet
ableorv
iewthatdat
awil
lbeinsert
edint
o.
Col
umn_
li
stl
i
stscol
umnst
hatwi
l
lbeaf
fect
edbyt
heI
NSERT.
I
facol
umni
somi
tt
ed,
eachv
aluemustbepr
ovi
ded.
I
fyouar
eincl
udi
ngcol
umns,
theycanbel
i
stedi
nanyor
der
.
VALUESspeci
fi
est
hedat
athaty
ouwantt
oinser
tint
othet
abl
e.VALUES
i
srequi
red.
Col
umnswit
htheIDENTITYproper
tyshoul
dnotbeexpl
i
cit
lyl
i
stedi
nthe
col
umn_
li
storval
ues_
clause.
Wheni
nser
ti
ngr
owswi
tht
heI
NSERTst
atement
,theser
ulesappl
y:
Inser
ti
nganempt
yst
ri
ng(
‘‘
)int
oav
archarort
extcol
umni
nser
tsa
singl
espace.
Al
lcharcol
umnsar
eri
ght
-paddedt
othedef
inedl
engt
h.
Allt
rai
li
ngspacesareremovedfr
om datainser
tedi
ntov
archarcol
umns,
excepti
nstr
ingsthatcont
ainonl
yspaces.Thesest
ri
ngsaretr
uncated
toasingl
espace.
I
fanINSERTstat
ementviol
atesaconst
rai
nt,
def
aul
torrule,
orifi
tist
he
wrongdat
aty
pe,thest
atementfai
lsandSQLSer
verdi
splaysanerr
or
message.
UPDATEst
atement
TheUPDATEst
atementchangesdat
ainexi
sti
ngr
owsei
therbyaddi
ng
newdat
aormodify
ingexi
sti
ngdata.
Thisexampl
eusestheUPDATEst
atementt
ost andardizet
hecount
ry
fi
eldtobeCanadaf
orall
recor
dsi
nthePubl
isherstable.
DELETEst
atement
TheDELETEstat
ementremovesrowsfrom arecor
dset.DELETEnames
thet
abl
eorviewthathol
dstherowsthatwi
llbedelet
edandonlyone
tableorrowmaybeli
stedatati
me.WHEREisast
andar
dWHERE
clausethatl
i
mit
sthedelet
iont
osel
ectr
ecor
ds.
Ther
ulesf
ort
heDELETEst
atementar
e:
I
fyouomitaWHEREcl ause,al
lrowsi
nthet
abl
ear
eremov
ed(
exceptf
or
i
ndexes,
thet
abl
e,constrai
nts)
.
DELETEcannotbeusedwi
thaviewthathasaFROM cl
ausenami
ng
morethanonetabl
e.(
Del
etecanaff
ectonlyonebaset
abl
eatati
me.
)
Quest
ionNo2
Somet imesmul ti
pleusersareaccessingthesamet abl
esatthesame
ti
me.I nthesesituati
ons,youneedt odecidewhentoall
owy our
applicat
iontoupdat ethedatabase.Ifyouall
owyourappli
cati
onto
al
way supdat
et hedatabaseitcouldov er
writ
echangesmadebyot her
users.Youcancont r
olwhenupdat essucceedbyspecifyi
ngwhich
columnsar eincludedintheWHEREcl auseofanUPDATEorDELETE
statement.
UPDATEt
abl
e..
.
SETcol
umn=newv
alue
WHEREcol
l=v
aluel
ANDcol
2=v
alue2
DELETE
FROM t
abl
e
WHEREcol
l=v
aluel
ANDcol
2=v
alue2
Considert
hissi
tuat
ion:
Yourappli
cat
ionisupdati
ngt heEMPLOYEEtabl
e,
whosekeyisEMP- I
D;al
lcolumnsinthetabl
eareupdat abl
e.Sayy
our
userhaschangedthesalar
yofemployee1001f r
om CHF50, 000t
oCHF
65,
000.Thisiswhathappenswit
hthediffer
entsett
ingsfortheWHERE
cl
ausecolumns:
I
fyouchooseKeyCol
umnsf
ort
heWHEREcl
ause,
t
heUPDATEst
atementl
ooksl
i
ket
his:
UPDATEempl
oyee
SETsal
ary=65000
WHEREemp-
id=1001
stat
ementwill
succeedr egardlessofwhetherot heruser
shavemodifi
ed
therowsinceyourappl
icati
onr etri
evedtherow.Forexampl e,
ifanot
her
userhadmodifi
edthesal ar
yt oCHF70, 000,thatchangewil
lbe
overwri
tt
enwheny ourapplicati
onupdatesthedat abase.
I
fyouchooseKeyandModifi
edCol
umnsf
ort
heWHEREcl
ause,
the
UPDATEstat
ementlooksl
i
kethi
s:
UPDATEempl
oyee
SETsal
ary=65000
WHEREemp-
id=1001
ANDsal
ary=50000
HeretheUPDATEst atementisalsochecki
ngtheorigi
nalv
al ueofthe
modifi
edcolumnintheWHEREcl ause.Thestat
ementwillfail
ifanot
her
userchangedthesalaryofemployee1001sinceyourappl
ication
ret
ri
evedtherow.
I
fyouchooseKeyandUpdat
eabl
eCol
umnsf
ort
heWHEREcl
ause,
t
heUPDATEst
atementl
ooksl
i
ket
his:
UPDATEempl
oyee
SETsal
ary=65000
WHEREemp-
id=1001
ANDsal
ary=50000
ANDf
name=or
igi
nal
-val
ue
ANDl
name=or
igi
nal
val
ue
ANDst
atus=or
igi
nal
val
ue;
Her
etheUPDATEst at
ementischeckingal
lupdatabl
ecolumnsint he
WHEREclause.Thi
sstat
ementwillf
aili
fanyoftheupdatabl
ecolumns
f
oremployee1001havebeenchangedsinceyourappli
cati
onret
rieved
t
herow.
Quest
ionNo3
Regar dlesoft hev ersi
onoftheDSDLC, t
herearemanyi nter
-relat
ed
stagest hatwor kt oachievecommonpur pose.Alt
houghthesest agesare
notnecessar i
lyexecut edi
nseri
alform,thei
rnaturedict
atesthat
theout comeofonest agedoesinf
luencetheoutcomeoft her est
.For
exampl eifthemi ssionisnotwell
knowni nadvance,sur
elyi
twi llbehar
d
todet erminet hesy stemsrequi
rementsandhencet hefail
uret o
thedev elopedsy stem.Therefor
eeachoft hestagesneedst obe
priot
ized.