SQL Chapter Two
SQL Chapter Two
tTwo:Dat
adef
ini
ti
onl
anguage
Thi
suni
tisdev
elopedt
opr
ovi
dey
out
henecessar
yinf
ormat
ionr
egar
dingt
hef
oll
owi
ng
cont
entcov
erageandt
opi
cs:
I
ntr
oduct
iont
oSQLdat
adef
ini
ti
onl
anguagecommands
Dat
abasepl
anni
ng
Nami
ngconv
ent
ionf
oral
ldat
abaseel
ement
s
Dat
abasest
ruct
urecr
eat
ionandmani
pul
ati
on
Thi
suni
twi
l
lal
soassi
sty
out
oat
tai
nthel
ear
ningout
comesst
atedi
nthecov
erpage.
Speci
fi
cal
ly
,uponcomplet
ionoft
hislear
ninggui
de,
youwi
l
lbeabl
eto:
Expl
ainDat
adef
init
ionl
anguage
I
dent
if
yDDLcommands
Appl
ySQLDDLt
ocr
eat
eandmani
pul
atedat
abasest
ruct
ures
I
dent
if
ythekeycomponent
sofar
elat
ional
dat
abase(
tabl
es,
rows,
col
umns)
.
Under
standt
heconceptoft
abl
erel
ati
onshi
ps(
e.g.
,one-
to-
many
,many
-to-
many
).
Ut
il
izeI
NNERJOI
N,LEFTJOI
N,RI
GHTJOI
N,andFULLJOI
Ntocombi
nedat
afr
om
mul
ti
plet
abl
es.
Def
ineandenf
orcedat
aint
egr
it
yusi
ngconst
rai
nts(
e.g.
,PRI
MARYKEY,FOREI
GN
KEY,
UNI
QUE)
.
Under
standt
hepur
poseofconst
rai
ntsi
nmai
ntai
ningdat
aqual
i
ty.
Under
standt
hepur
poseandbenef
it
sofcr
eat
ingv
iews
BASI
CSTRUCTUREQUERYLANGUAGE RIFTVALLEYUNI
VERSI
TYNEKEMTETVETCOLLAGE
2024 FI
RSTEDI
TED
I
NSTRUCTORBYMR:-
GEMECHUAPAGE1
2.
1.I
ntr
oduct
iont
oSQLdat
adef
ini
ti
onl
anguagecommands
TheDat
aDef
ini
ti
onLanguage(
DDL)i
spar
tofSQLt
haty
ouuset
ocr
eat
e(compl
etel
ydef
ine)a
dat
abase,
modi
fyi
tsst
ruct
ure,
anddest
royi
twheny
ounol
ongerneedi
t.
I
tcont
ainsSQLcommandsy
ouuset
ocr
eat
e,change,ordest
royt
hebasi
cel
ement
sofa
r
elat
ionaldat
abase.Basi
cel
ement
sincl
udet
abl
es,v
iews,schemas,cat
alogs,cl
ust
ers,i
ndexes,
st
oredpr
ocedur
es,f
unct
ionsandpossi
blyot
hert
hingsaswel
l
.Int
hissect
ion,y
ouwi
l
lsee
cont
ainmenthi
erar
chyt
hat
r
elat
est
heseel
ement
stoeachot
herandl
ookatt
hecommandst
hatoper
ateont
heseel
ement
s.
Schemai
sanov
eral
lst
ruct
uret
hati
ncl
udest
abl
eswi
thi
nit
.Tabl
esandschemasar
etwo
el
ement
sofar
elat
ionaldat
abase’
scont
ainmenthi
erar
chy
.Youcanbr
eakdownt
hecont
ainment
hi
erar
chyasf
oll
ows:
Tabl
escont
aincol
umnsandr
ows.
Schemascont
aint
abl
esandv
iews.
Cat
alogscont
ainschemas.
Thedat
abasei
tsel
fcont
ainscat
alogs.Somet
imest
hedat
abasei
sref
err
edt
oasacl
ust
er.
Adat
abaset
abl
eisat
wo-
dimensi
onal
arr
aymadeupofr
owsandcol
umns.Youcancr
eat
ea
t
abl
ebyusi
ngt
heSQLCREATETABLEcommand.Wi
thi
nthecommand,
youspeci
fyt
hename
anddat
aty
peofeachcol
umn.Af
tery
oucr
eat
eat
abl
e,y
oucanst
artl
oadi
ngi
twi
thdat
a.
(
Loadi
ngdat
aisaDML,
notaDDL,
funct
ion.
).I
frequi
rement
schange,
youcanchangeat
abl
e’
s
st
ruct
urebyusi
ngt
heALTERTABLEcommand.I
fat
abl
eout
li
vesi
tsusef
ulnessorbecomes
obsol
ete,
youcanel
i
minat
eitwi
tht
heDROPcommand.Thev
ari
ousf
ormsoft
heCREATEand
BASI
CSTRUCTUREQUERYLANGUAGE RIFTVALLEYUNI
VERSI
TYNEKEMTETVETCOLLAGE
2024 FI
RSTEDI
TED
I
NSTRUCTORBYMR:-
GEMECHUAPAGE2
ALTERcommands,
toget
herwi
tht
heDROPcommand,
makeupSQL’
sDDL.
2.
2.Dat
abasepl
anni
ng
Sayt
haty
ouneedt
ocr
eat
eadat
abasef
ory
ouror
gani
zat
ion.Exci
tedbyt
hepr
ospectofbui
l
ding
ausef
ul,
val
uabl
e,andt
otal
l
yri
ght
eousst
ruct
ureofgr
eati
mpor
tancet
oyourcompany
’sf
utur
e,
y
ousi
tdownaty
ourcomput
erandst
artent
eri
ngSQLCREATEcommands.Ri
ght
?Wel
l
,no.Not
qui
te.I
nfact
,that
’sapr
escr
ipt
ionf
ordi
sast
er.Manydat
abasedev
elopmentpr
oject
sgoawr
y
f
rom t
hest
artasexci
tementandent
husi
asm ov
ert
akecar
eful
planni
ng.Ev
eni
fyouhav
eacl
ear
i
deaofhowt
ost
ruct
ure
y
ourdat
abase,
wri
teev
ery
thi
ngdownonpaperbef
oret
ouchi
ngy
ourkey
boar
d.Keepi
nmi
ndt
he
f
oll
owi
ngpr
ocedur
eswhenpl
anni
ngy
ourdat
abase:
I
dent
if
yal
ltabl
es.
Def
inet
hecol
umnst
hateacht
abl
emustcont
ain.
Gi
veeacht
abl
eapr
imar
ykeyt
haty
oucanguar
ant
eei
suni
que.
Makesur
ethatev
eryt
abl
eint
hedat
abasehasatl
eastonecol
umni
ncommonwi
thone
ot
hert
abl
eint
hedat
abase.Theseshar
edcol
umnsser
veasl
ogi
cal
li
nkst
hatenabl
eyou
t
orel
atei
nfor
mat
ioni
nonet
abl
etot
hecor
respondi
ngi
nfor
mat
ioni
nanot
hert
abl
e.
Puteacht
abl
eint
hir
dnor
mal
for
m(3NF)orbet
tert
oensur
ethepr
event
ionofi
nser
ti
on,
del
eti
on,
andupdat
eanomal
i
es.Af
tery
oucompl
etet
hedesi
gnonpaperandv
eri
fyt
hati
t
i
ssound,
you’
rer
eadyt
otr
ansf
ert
hedesi
gnt
othecomput
erbyusi
ngSQLCREATE
commands.
2.
3.Usageofr
elev
antnami
ngconv
ent
ionf
oral
ldat
abaseel
ement
s
Theobj
ect
sinaSQL-
baseddat
abasear
eident
if
iedbyassi
gni
ngt
hem uni
quenames.
Namesar
eusedi
nSQLst
atement
stoi
dent
if
ythedat
abaseobj
ectonwhi
cht
hest
atement
shoul
dact
.
TheANSI
/I
SOSQLst
andar
dspeci
fi
est
abl
esnames(
whi
chi
dent
if
ytabl
es)
,col
umnnames
BASI
CSTRUCTUREQUERYLANGUAGE RIFTVALLEYUNI
VERSI
TYNEKEMTETVETCOLLAGE
2024 FI
RSTEDI
TED
I
NSTRUCTORBYMR:-
GEMECHUAPAGE3
(
whi
chi
dent
if
ycol
umns)
,andusernames(
whi
chi
dent
if
yuser
soft
hedat
abase)
TheSQLdat
abaseNameshoul
dnotbeempt
yandspeci
alchar
act
ers.TheANSI
/I
SO
st
andar
dsspeci
fi
est
hatSQLnamesmustcont
ain1t
o18char
act
ers,begi
nwi
thal
ett
er,
andmynotcont
ainanyspacesorspeci
alpunct
uat
ionchar
act
ers.
Tabl
eName
Wheny
ouspeci
fyat
abl
enamei
naSQLst
atement
,SQLassumest
haty
ouar
eref
err
ing
t
ooneofy
ourownt
abl
es(
thati
s,at
abl
ethaty
oucr
eat
ed)
.Wi
tht
hepr
operper
missi
on,
y
oucanal
sor
efert
otabl
esownedbyot
heruser ngaqual
susi if
iedt
abl
ename.
Col
umnName
Wheny
ouspeci
fyacol
umnnamei
naSQLst
atement
,SQLcannor
mal
l
ydet
ermi
ne
f
rom t
hecont
extwhi
chcol
umny
oui
ntend.Acol
umnnameshoul
dnotbebl
ankand
t
hesamei
nthesamedat
abase.
Dat
aTy
pes
Ther
eisast
andar
dthatspeci
fi
esv
ari
oust
ypesofdat
athatcanbest
oredi
nSQL-
baseddat
abaseandmani
pul
atedbyt
heSQLl
anguages.
Char
act
erst
ri
ngs:
Dat
aty
pe Descr
ipt
ion St
orage
char
(n) or Fi
xed-
lengt
hchar
act
erst
ri
ng.
Maxi
mum8,
000char
act
ers N
char
act
er(
n)
BASI
CSTRUCTUREQUERYLANGUAGE RIFTVALLEYUNI
VERSI
TYNEKEMTETVETCOLLAGE
2024 FI
RSTEDI
TED
I
NSTRUCTORBYMR:-
GEMECHUAPAGE4
v
archar
(n) Var
iabl
e-l
engt
hchar
act
erst
ri
ng.
Maxi
mum8,
000char
act
ers
v
archar
(max
) Var
iabl
e-l
engt
h char
act
erst
ri
ng.Maxi
mum 1,
073,
741,
824
char
act
ers
Tex
t Var
iabl
e-l
engt
hchar
act
erst
ri
ng.
Maxi
mum2GBoft
extdat
a
Uni
codest
ri
ngs:
Dat
aty
pe Descr
ipt
ion St
orage
nchar
(n) Fi
xed-
lengt
hUni
codedat
a.Maxi
mum4,
000char
act
ers
nv
archar
(n) Var
iabl
e-l
engt
hUni
codedat
a.Maxi
mum4,
000char
act
ers
nv
archar
(max
) Vari
abl
e-l
engt
h Uni
code dat
a. Maxi
mum 536,
870,
912
char
act
ers
Nt
ext Var
iabl
e-l
engt
hUni
codedat
a.Maxi
mum2GBoft
extdat
a
Bi
nar
yty
pes:
BASI
CSTRUCTUREQUERYLANGUAGE RIFTVALLEYUNI
VERSI
TYNEKEMTETVETCOLLAGE
2024 FI
RSTEDI
TED
I
NSTRUCTORBYMR:-
GEMECHUAPAGE5
Dat
aty
pe Descr
ipt
ion St
orag
e
Bi
t Al
l
ows0,
1,orNULL
bi
nar
y(n) Fi
xed-
lengt
hbi
nar
ydat
a.Maxi
mum8,
000by
tes
v
arbi
nar
y(n) Var
iabl
e-l
engt
hbi
nar
ydat
a.Maxi
mum8,
000by
tes
v
arbi
nar
y(max
) Var
iabl
e-l
engt
hbi
nar
ydat
a.Maxi
mum2GB
I
mage Var
iabl
e-l
engt
hbi
nar
ydat
a.Maxi
mum2GB
Numbert
ypes:
Dat
aty
pe Descr
ipt
ion St
orage
Ti
nyi
nt Al
l
owswhol
enumber
sfr
om 0t
o255 1by
te
Smal
l
int Al
l
owswhol
enumber
sbet
ween-
32,
768and32,
767 2by
tes
I
nt Al
lows whole number
s bet
ween -
2,147,
483,
648 and 4by
tes
2,
147,
483,
647
Bi
gint Al
l
owswhol
enumber
sbet
ween-
9,223,
372,
036,
854, 808 8by
775, tes
and9,
223,
372,
036,
854,
775,
807
BASI
CSTRUCTUREQUERYLANGUAGE RIFTVALLEYUNI
VERSI
TYNEKEMTETVETCOLLAGE
2024 FI
RSTEDI
TED
I
NSTRUCTORBYMR:-
GEMECHUAPAGE6
deci
mal
(p,
s) Fi
xedpr
eci
si
onandscal
enumber
s. 5-
17
by
tes
Al
l
owsnumber
sfr
om -
10^
38+1t
o10^
38–1.
Theppar
amet
eri
ndi
cat
est
hemaxi
mum t
otalnumberof
di
git
sthatcanbest
ored(
bot
htot
hel
eftandt
other
ightof
t
hedeci
mal
poi
nt)
.pmustbeav
aluef
rom 1t
o38.Def
aul
tis
18.
Thesparamet
eri
ndi
cat
est
hemaxi
mum numberofdi
git
s
st
oredt
o
BASI
CSTRUCTUREQUERYLANGUAGE RIFTVALLEYUNI
VERSI
TYNEKEMTETVETCOLLAGE
2024 FI
RSTEDI
TED
I
NSTRUCTORBYMR:-
GEMECHUAPAGE7
t
her
ightoft
hedeci
malpoi
nt.smustbeav
aluef
rom 0t
op.
Def
aul
tval
uei
s0
numer
ic(
p,s) Fi
xedpr
eci
si
onandscal
enumber
s. 5-
17
by
tes
Al
l
owsnumber
sfr
om -
10^
38+1t
o10^
38–1.
Theppar
amet
eri
ndi
cat
est
hemaxi
mum t
otalnumberof
di
git
sthatcanbest
ored(
bot
htot
hel
eftandt
other
ightof
t
hedeci
mal
poi
nt)
.pmustbeav
aluef
rom 1t
o38.Def
aul
tis
18.
Thespar
amet
eri
ndi
cat
est
hemaxi
mum numberofdi
git
s
st
oredt
other
ightoft
hedeci
malpoi
nt.smustbeav
alue
f
rom 0t
op.
Def
aul
tval
ueis0
Smal
l
money Monet
arydat
afr
om -
214,
748.
3648t
o214,
748.
3647 4by
tes
Money Monet
ary dat
a f
rom -
922,
337,
203,
685,
477. o 8by
5808 t tes
922,
337,
203,
685,
477.
5807
f
loat
(n) Fl
oati
ngpr
eci
si
onnumberdat
afr
om -
1.79E+308t
o1.
79E+ 4 or 8
308.
by
tes
Thenpar
amet
eri
ndi
cat
eswhet
hert
hef
iel
dshoul
dhol
d4or
8by
tes.f
loat
(24)hol
dsa4-
byt
efi
eldandf
loat
(53)hol
dsan
8-
byt
efi
eld.Def
aul
tval
ueofni
s53.
Real Fl
oat
ingpr
eci
si
onnumberdat
afr
om -
3.40E+38t
o3.
40E+ 4by
tes
38
Dat
ety
pes:
BASI
CSTRUCTUREQUERYLANGUAGE RIFTVALLEYUNI
VERSI
TYNEKEMTETVETCOLLAGE
2024 FI
RSTEDI
TED
I
NSTRUCTORBYMR:-
GEMECHUAPAGE8
Dat
aty
pe Descr
ipt
ion St
orage
Dat
eti
me Fr
om January1,1753t
oDecember31,
9999wi
t acyof 8by
hanaccur tes
3.
33mill
iseconds
dat
eti
me2 From Januar
y1,0001andDecember31,9999wi
t acy 6-
hanaccur 8by
tes
of100nanoseconds
Smal
ldat
eti
me Fr
om January1,1900toJune6,2079wi
thanaccuracyof1 4by
tes
minut
e
Dat
e St
oreadateonl
y.Fr
om Januar
y1,
0001t
oDecember31,
9999 3by
tes
Ti
me St
oreat
imeonl
ytoanaccur
acyof100nanoseconds 3-
5by
tes
Dat
eti
meof
fsetThesameasdat
eti
me2wi
tht
headdi
ti
onofat
imezoneof
fset 8-
10by
tes
Ti
mest
amp St
oresauni quenumberthatgetsupdatedev er
ytimearowget
s
cr
eated ormodi f
ied.Thetimestamp v al
uei sbaseduponan
i
nter
nalclockanddoesnotcor respondt orealti
me.Eacht
abl
e
mayhaveonl yonetimest
ampv ari
able
BASI
CSTRUCTUREQUERYLANGUAGE RIFTVALLEYUNI
VERSI
TYNEKEMTETVETCOLLAGE
2024 FI
RSTEDI
TED
I
NSTRUCTORBYMR:-
GEMECHUAPAGE9
Ot
herdat
aty
pes:
Dat
aty
pe Descr
ipt
ion
sql
_var
iant St
oresupto8,000byt
esofdat
aofv
ari
ousdat
aty
pes,exceptt
ext
,
nt
ext,
andt
imestamp
uni
quei
dent
if
ier St
oresagl
obal
l
yuni
quei
dent
if
ier(
GUI
D)
Xml St
oresXMLf
ormat
teddat
a.Maxi
mum 2GB
Cur
sor St
oresar
efer
encet
oacur
sorusedf
ordat
abaseoper
ati
ons
Tabl
e St
oresar
esul
t-
setf
orl
aterpr
ocessi
ng
Fi
xed-
lengt
hchar
act
erst
ri
ngs:col
umnshol
dingt
heset
ypesofdat
aty
pical
l
y
st
orenamesofpeopl
eandcompani
es,
addr
esses,
descr
ipt
ions,
andsoon.
I
nteger
s:col
umnshol
dingt
hist
ypesofdat
aty
pical
l
yst
orecount
s,quant
it
ies,
ages,and so on.I
nteger
’scol
umnsar
eal
so f
requent
lyused t
o cont
ainI
d
number
s,suchascust
omer
s,empl
oyee.Andor
dernumber
s.
Deci
malnumber
s:col
umnswi
tht
hist
ypest
orenumber
sthathav
efr
act
ional
par
tsandmustbecal
cul
atedexact
ly,suchasr
atesandper
cent
ages.Theyar
e
al
sof
requent
lyusedt
ost
oremoneyamount
s.
Ext
endeddat
aTy
pes
Var
iabl
e-l
engt
hChar
act
erst
ri
ng:SQLwhi
chsuppor
tsVARCHATdat
a.Whi
ch
al
l
owsacol
umnt
ost
orechar
act
erst
ri
ngst
hatv
aryi
nlengt
hfr
om r
owt
orow,
upt
o
somemaxi
mum l
engt
h.
Dat
esandt
imes:
suppor
tsf
ordat
e/t
imev
alues.
Bool
eandat
a:suppor
tsl
ogi
cal
(TRUEorFALSE)v
aluesasanexpl
i
citt
ype.
Dat
aTy
pesDi
ff
erences
BASI
CSTRUCTUREQUERYLANGUAGE RIFTVALLEYUNI
VERSITYNEKEMTETVETCOLLAGE
2024 FI
RSTEDI
TED
INSTRUCTORBYMR:
-GEMECHUAPAGE10
Thedi
ff
erencesb/
nthedat
aty
pesof
fer
edi
nvar
iousSQLi
mpl
ement
ati
oni
soneoft
he
pr
act
ical
bar
ri
erst
othepor
tabi
l
ityofSQLbasedappl
i
cat
ions.
Ex
ampl
e:Dat
e/t
imedat
apr
ovi
desanexcel
l
entexampl
eoft
hesesdi
ff
erences.
Dat
e:w/
cst
oresadat
elkeJune30,
i 2009 or 30June2009
Const
ant
s
I
nsomeSQLst
atement
sanumer
ic,char
act
er,ordat
edat
aval
uemustbeexpr
essedi
ntex
t
f
orm.
Forexampl
e:I
NSERTst
atement
,w/
caddsast
udentt
othedat
abase:
I
NSERTI
NTO st
udent
(Fname,SI
D,Dept
,
year)VALUES(
‘Al
emay
ehu’
,200,‘
Comp
Science’
,2)
Theval
ueforeachcol
umnint
henewlyi
nsertedrowisspeci
fi
edi
ntheVALUESclause.
Const
antdat
av al
uesar
eal
sousedi
nexpressionsuchasint
heSELECTst
atement
SELECTci
ty
FROM
of
fi
ces
Numer
icconst
ant
I
nteger
s and deci
malconstant
s (also cal
led exactnumericlit
eral
s)are wr
it
ten as
or
dinar
ydeci
mal number
sinSQLstat
ements,wit
hanoptional
leadi
ngplusormi
nussign
Ex
ampl
e:200 +345.
95 -
500 789.
00
Useacommabet
weent
hedi
git
sofanumer
icconst
ant
St
ri
ngConst
ant
BASI
CSTRUCTUREQUERYLANGUAGE RIFTVALLEYUNI
VERSITYNEKEMTETVETCOLLAGE
2024 FI
RSTEDI
TED
INSTRUCTORBYMR:
-GEMECHUAPAGE11
TheANSI
/I
SOst
andar
dspeci
fi
est
hatSQLconst
ant
sforchar
act
erdat
abeencl
osedi
nsi
ngl
e
quot
es
(
‘……’
)
Exampl
e:‘
Waksum Mot
uma’‘
Addi
sAbaba’
Ifasingl
equot
esi
st obeusedincl
udedintheconstantt
ext
,iti
swritt
enwit
hint
he
const
antast
woconsecut
ivesi
ngl
equotechar
act
ers.Thi
sisconst
antv
alue:
Exampl
e:“
Ican’
t”
Dat
eandt
imeconst
ant
s
I
nSQLpr oduct
st hesupportsdat
e/t
imedata.Const
antval
uesfordates,ti
mes,and
t
imeinter
val
sarespecif
iedasstri
ngconst
ants.Thefor
matoftheseconstant
svari
es
f
rom oneDBMSt othenext.
Exampl
e:
FROM st
udent
WHEREhi
re-
dat
e=To-
dat
e(‘
June30,
2009’
,‘
monDDy
yyy
’)
Expr
essi
ons
Expressi
onsareusedintheSQLLanguagestocal
cul
ateval
uesthatar
eret
ri
evedf
rom
thedatabaseandtocalcul
atev
aluesusedi
nsearchi
ngthedat
abase.
Exampl
e1:Thequer
ythatcal
cul
atest
hesal
esofeachof
fi
cesasaper
cent
ageofi
tst
arget
:
SELECT ci
ty, t
arget
,
sal
es,
(sal
es/
tar
get
)*100FROM of
fi
ces
BASI
CSTRUCTUREQUERYLANGUAGE RIFTVALLEYUNI
VERSITYNEKEMTETVETCOLLAGE
2024 FI
RSTEDI
TED
INSTRUCTORBYMR:
-GEMECHUAPAGE12
Exampl
e2:
SELECT ci
ty
FROMoffi
ces
WHEREsal
es>t
arget+50000.
00
Mi
ssi
ngdat
a(Nul
lVal
ues)
I
tisav
aluewhosev
aluei
smi
ssi
ng,
unknown,
ordon’
tappl
y.
SQLsuppor
tsmi
ssi
ng,
unknown,
ori
nappl
i
cabl
edat
aexpl
i
cit
lyt
hrought
heconcept
sof
nul
lval
ues.
AnullValuei
sani
ndi
cat
ort
hatt
ell
sSQL(
andt
heuser
)thatt
hedat
aismi
ssi
ngornot
appl
i
cable.
BASI
CSTRUCTUREQUERYLANGUAGE RIFTVALLEYUNI
VERSITYNEKEMTETVETCOLLAGE
2024 FI
RSTEDI
TED
INSTRUCTORBYMR:
-GEMECHUAPAGE13
Exampl
e:gi
venast
udentt
abl
ebel
owt
hathasmi
ssi
ngv
alues
2.
4.Dat
abasest
ruct
urecr
eat
ionandmani
pul
ati
on
Remembert
hatadat
abasei
sdesi
gned,
bui
l
tandpopul
atedwi
thdat
aforaspeci
fi
c
pur
poset
hati
sdesi
gnedt
oaddr
essaspeci
fi
cpr
obl
em i
nther
eal
wor
ld.
Oncey
ouhav
ecompl
eteddat
abasedesi
gn,
youcani
mpl
ementi
tusi
ngaspeci
fi
cDBMS.
Youmay
,forexampl
e,cr
eat
eaCUSTOMERt
abl
ewi
tht
heat
tr
ibut
es
CUSTOMER.
Cust
omer
ID,CUSTOMER.
Fir
stName,
CUSTOMER.
Last
Name,
CUSTOMER.
Str
eet
,CUSTOMER.
Cit
y,CUSTOMER.
Stat
e,CUSTOMER.
Zipcode,
and
CUSTOMER.
Phone.Al
loft
heseat
tri
but
esar
emor
ecl
osel
yrel
atedt
othecust
omer
ent
it
ythant
oanyot
herent
it
yinadat
abaset
hatmaycont
ainmanyt
abl
es.These
at
tr
ibut
escont
ainal
lther
elat
ivel
yper
manentcust
omeri
nfor
mat
iont
haty
our
or
gani
zat
ionkeepsonf
il
e.Mostdat
abasemanagementsy
stemspr
ovi
deagr
aphi
cal
t
ool
forcr
eat
ingdat
abaset
abl
es.YouuseSQLSer
vermanagementst
udi
owhi
chi
sa
gr
aphi
cal
tool
prov
idedbyMi
crosof
ttoconnectt
oMSSQLSer
verf
orcr
eat
ingdat
abase
t
abl
esYoucanal
socr
eat
esucht
abl
esbyusi
nganSQLcommand.Si
nceadat
abase
cont
ainsal
lot
herobj
ect
sincl
udi
ngt
abl
es,
youneedt
ocr
eat
edat
abasef
ir
stbef
orey
ou
cr
eat
etabl
esandot
herobj
ect
s.
TheSQLCREATEDATABASEst
atementi
susedt
ocr
eat
enewSQLdat
abase.
BASI
CSTRUCTUREQUERYLANGUAGE RI FTVALLEYUNI
VERSI
TYNEKEMTETVET
COLLAGE2024 FI
RSTEDITED
I
NSTRUCTORBYMR:-
GEMECHUAPAGE14
Sy
ntax
:
Basi
csy
ntaxofCREATEDATABASEst
atementi
sasf
oll
ows:
CREATEDATABASEDat
abaseName;
Al
way
sdat
abasenameshoul
dbeuni
quewi
thi
ntheRDBMS.
Exampl
e:
I
fyouwantt
ocr
eat
enew dat
abase<t
est
DB>,t
henCREATEDATABASEst
atement
woul
dbeasf
oll
ows:
Eg.Cr
eat
edat
abaset
est
DB
Youneedt
oexecut
ethecommandt
ocr
eat
ethespeci
fi
eddat
abase.Oncey
oucr
eat
ea
dat
abaseandmadei
ttheact
ive(
cur
rent
lysel
ect
ed)dat
abase,nowy
oucancr
eat
eas
manyobj
ect
sasy
ouwanti
ncl
udi
ngt
abl
es.Thef
oll
owi
ngexampl
edemonst
rat
esa
commandt
hatcr
eat
esy
ourCUSTOMERt
abl
e:
CREATETABLECUSTOMER(
cust
omer
idI
NTEGERNOTNULL,f
ir
stnameCHARACTER
(
15)
,last
nameCHARACTER(
20)NOTNULL,
Str
eetCHARACTER(
25)
,Ci
tyCHARACTER
(
20)
,St
ateCHARACTER(
2),
ZipcodeI
NTEGER,
PhoneCHARACTER(
13));
Foreachcol
umn,y
ouspeci
fyi
tsname(
forexampl
e,Cust
omer
ID)
,it
sdat
aty
pe(
for
exampl
e,I
NTEGER)
,andpossi
blyoneormor
econst
rai
nts(
forexampl
e,NOTNULL)
.
Vi
ew:
-Att
imes,
youwantt
oret
ri
evespeci
fi
cinf
ormat
ionf
rom t
heCUSTOMERt
abl
e.
Youdon’
twantt
olookatev
ery
thi
ng—onl
yspeci
fi
ccol
umnsandr
ows.Whaty
ouneed
i
sav
iew.
Av
iewi
sav
irt
ualt
abl
e.I
nmosti
mpl
ement
ati
ons,av
iewhasnoi
ndependentphy
sical
exi
stence.Thev
iew’
sdef
ini
ti
onexi
stsonl
yint
hedat
abase’
smet
adat
a,butt
hedat
a
comesf
rom t
het
abl
eort
abl
esf
rom whi
chy
ouder
ivet
hev
iew.Thev
iew’
sdat
aisnot
phy
sical
l
ydupl
i
cat
edsomewher
eel
sei
nonl
i
nedi
skst
orage.Somev
iewsconsi
stof
speci
fi
ccol
umnsandr
owsofasi
ngl
etabl
e.Ot
her
s,knownasmul
tit
abl
evi
ews,dr
aw
BASI
CSTRUCTUREQUERYLANGUAGE RI FTVALLEYUNI
VERSI
TYNEKEMTETVET
COLLAGE2024 FI
RSTEDITED
I
NSTRUCTORBYMR:-
GEMECHUAPAGE15
f
rom t
woormor
etabl
es.Eg.OfSQLDDLst
atementt
ocr
eat
eav
iew
CREATEVI
EW NH_
CUSTASSELECTCUSTOMER.
Fir
stName,
CUSTOMER.
Last
Name,
CUSTOMER.
PhoneFROM CUSTOMER WHERECUSTOMER.
Stat
e=‘
NH’
Rel
ati
onshi
ps
I
fonet
abl
einadat
abasecont
ainsasaf
orei
gnkeyacol
umnt
hati
sapr
imar
ykeyi
n
anot
hert
abl
eint
hedat
abase,y
oucanaddaconst
rai
ntt
othef
ir
stt
abl
esot
hati
t
r
efer
encest
hesecondt
abl
e.
Exampl
e:
CREATETABLECUSTOMERS(
IDI
NTNOTNULL,NAMEVARCHAR(
20)NOTNULL,AGE
I
NTNOTNULL,
ADDRESSCHAR(
25),
SALARYDECI
MAL(
18,
2),PRI
MARYKEY(
ID))
;
CREATETABLEORDERS(
IDI
NTNOTNULL,O_
DATEDATETI
ME,CUSTOMER_
IDI
NT
f
orei
gnkeyr
efer
encesCUSTOMERS(
ID)
,AMOUNTDeci
mal
(8,
2),
PRI
MARYKEY(
ID)
);
Fordef
ini
ngaPRI
MARYKEYconst
rai
ntonmul
ti
plecol
umns,uset
hef
oll
owi
ngSQL
sy
ntax:
CREATETABLECUSTOMERS(
IDI
NTNOTNULL,NAMEVARCHAR(
20)NOTNULL,AGE
I
NTNOTNULL,ADDRESSCHAR(
25)
,SALARYDECI
MAL(
18,2)
,PRI
MARYKEY(
ID,
NAME)
);
CHECKConst
rai
nt:
TheCHECK Const
rai
ntenabl
esacondi
ti
ont
o checkt
hev
aluebei
ng ent
ered i
nto
ar
ecor
d.I
fthecondi
ti
onev
aluat
est
ofal
se,
ther
ecor
dvi
olat
est
heconst
rai
ntandi
sn’
t
ent
eredi
ntot
het
abl
e.
Exampl
e:
Forexampl
e,t
hef
oll
owi
ngSQLcr
eat
esanewt
abl
ecal
l
edCUSTOMERSandaddsf
ive
BASI
CSTRUCTUREQUERYLANGUAGE RI FTVALLEYUNI
VERSI
TYNEKEMTETVET
COLLAGE2024 FI
RSTEDITED
I
NSTRUCTORBYMR:-
GEMECHUAPAGE16
col
umns.Her
e, weaddaCHECKwi
thAGEcol
umn,sot
haty
oucannothav
eany
CUSTOMERbel
ow18y
ear
s:
CREATETABLECUSTOMERS(
IDI
NTNOTNULL,
NAMEVARCHAR(
20)NOTNULL,
AGEI
NTNOTNULLCHECK(
AGE>=18)
,ADDRESSCHAR(
25),
SALARYDECI
MAL(
18,
2),
PRI
MARYKEY(
ID)
);
SQLNOTNULLConst
rai
nt
Bydef
aul
t,at
abl
ecol
umncanhol
dNULLv
alues.
TheNOTNULLconst
rai
ntenf
orcesacol
umnt
oNOTacceptNULLv
alues.
TheNOTNULLconst
rai
ntenf
orcesaf
iel
dtoal
way
scont
ainav
alue.
Thi
smeanst
haty
oucannoti
nser
tanewr
ecor
d,orupdat
ear
ecor
d
wi
thoutaddi
ngav
aluet
othi
sfi
eld.
Thef
oll
owi
ngSQLenf
orcest
he"
P_I
d"col
umnandt
he"
Last
Name"
CREATETABLEPer
sons
(
P_Idi
ntNOTNULL,
Last
Name varchar(
255) NOT NULL,
Fi
rst
Namev
archar(
255),
Address
varchar
(255)
, Ci ty
varchar
(255)
)
columnt onotacceptNULLv
alues:
SQLUNI
QUEConst
rai
nt
TheUNI
QUEconst
rai
ntuni
quel
yident
if
ieseachr
ecor
dinadat
abaset
abl
e.
TheUNI
QUEandPRI
MARYKEYconst
rai
ntsbot
hpr
ovi
deaguar
ant
ee
f
oruni
quenessf
oracol
umnorsetofcol
umns.
APRI
MARYKEYconst
rai
ntaut
omat
ical
l
yhasaUNI
QUEconst
rai
ntdef
inedon
i
t.
Not
ethaty
oucanhav
emanyUNI
QUEconst
rai
ntspert
abl
e,butonl
y
BASI
CSTRUCTUREQUERYLANGUAGE RI FTVALLEYUNI
VERSI
TYNEKEMTETVET
COLLAGE2024 FI
RSTEDITED
I
NSTRUCTORBYMR:-
GEMECHUAPAGE17
onePRI
MARYKEYconst
rai
ntpert
abl
e.
SQLUNI
QUEConst
rai
ntonCREATETABLE
The f
oll
owi
ng SQL cr
eat
es a UNI
QUE const
rai
nton t
he "
P_I
d"col
umn when t
he
"
Per
sons"t
abl
eiscr
eat
ed:
CREATETABLEPer
sons(
P_I
dintNOTNULLUNI
QUE,
Last
Namev
archar
(255)NOTNULL,
Fir
stNamev
archar
(255)
,
Address
var
char(
255)
, Ci
ty
var
char(
255)
)
Toal
l
ow nami
ngofaUNI
QUEconst
rai
nt,andf
ordef
ini
ngaUNI
QUEconst
rai
nton
mul
ti
plecol
umns,
uset
hef
oll
owi
ngSQLsy
ntax
:
CREATETABLEPer
sons(
P_I
dintNOTNULL,
Last
Namev
archar
(255)NOTNULL,
Fir
stNamev
archar
(255)
,
Addr
essv
archar
(255)
,Ci
tyv
archar
(255)
,
CONSTRAI
NTuc_
Per
sonI
DUNI
QUE(
P_I
d,Last
Name)
)
SQLDEFAULTConst
rai
nt
TheDEFAULTconst
rai
nti
susedt
oinser
tadef
aul
tval
uei
ntoacol
umn.
Thedef
aul
tval
uewi
l
lbeaddedt
oal
lnewr
ecor
ds,
ifnoot
herv
aluei
sspeci
fi
ed.
Thef
oll
owi
ngSQLcr
eat
esaDEFAULTconst
rai
ntont
he"
Cit
y"col
umnwhen
t
he“
Per
sons"t
abl
eiscr
eat
ed:
BASI
CSTRUCTUREQUERYLANGUAGE RI FTVALLEYUNI
VERSI
TYNEKEMTETVET
COLLAGE2024 FI
RSTEDITED
I
NSTRUCTORBYMR:-
GEMECHUAPAGE18
Create tabl
e per
sons(
P_I
d i
nt NOT NULL, Last
Name
varchar
(255)
NOTNULL,
Fir
stNamev
archar
(255)
,Addr
essv
archar
(255)
,
Ci
tyv
archar
(255)DEFAULT'
Sandnes'
)
TheDEFAULTconst
rai
ntcanal
sobeusedt
oinser
tsy
stem v
alues,byusi
ngf
unct
ions
l
ikeGETDATE(
):
CREATETABLEOr
der
s(O_
Idi
ntNOTNULL,Or
der
Noi
ntNOT
NULL,
P_I
dint
,Or
der
Dat
edat
eDEFAULTGETDATE(
))
SQLAUTOI
NCREMENTFi
el
d
Aut
o-i
ncr
emental
l
owsauni
quenumbert
obegener
atedwhenanewr
ecor
dis
i
nser
tedi
ntoat
abl
e.
AUTOI
NCREMENTaFi
el
d
Ver
yof
tenwewoul
dli
ket
hev
alueoft
hepr
imar
ykeyf
iel
dtobecr
eat
ed
aut
omat
ical
l
yev
eryt
imeanewr
ecor
disi
nser
ted.
Wewoul
dli
ket
ocr
eat
eanaut
o-i
ncr
ementf
iel
dinat
abl
e.
Sy
ntaxf
orSQLSer
ver
The f
oll
owi
ng SQL st
atementdef
ines t
he "
P_I
d"col
umn t
o be an aut
o-
BASI
CSTRUCTUREQUERYLANGUAGE RI FTVALLEYUNI
VERSI
TYNEKEMTETVET
COLLAGE2024 FI
RSTEDITED
I
NSTRUCTORBYMR:-
GEMECHUAPAGE19
i
ncr
ementpr
imar
ykeyf
iel
dint
he"
Per
sons"t
abl
e:
CREATETABLEPer
sons
(
P_
Idi
ntPRI
MARYKEYI
DENTI
TY,
Last
Name v
archar
(255) NOT NULL,
Fi
rst
Namev
archar
(255)
,
Addr
ess
v
archar
(255)
, Ci
ty
TheMSSQLSer
v heI
erusest DENTI
TYkeywor
dtoper
for
m anaut
o-i
ncr
ementf
eat
ure.
Bydef
aul
t,t
hest
art
ingv
aluef
orI
DENTI
TYi
s1,
andi
twi
l
lincr
ementby1f
oreach
newr
ecor
d.
Tospeci
fyt
hatt
he"
P_I
d"col
umnshoul
dst
artatv
alue10andi
ncr
ementby5,
changet
hei
dent
it
ytoI
DENTI
TY(
10,
5).
Toi
nser
tanewr
ecor
dint
othe"
Per
sons"t
abl
e,wewi
l
lnothav
etospeci
fyav
alue
f
ort
he"
P_I
d"col
umn(
auni
quev
aluewi
l
lbeaddedaut
omat
ical
l
y):
I
NSERT I
NTO Per
sons (
Fir
stName,
Last
Name)
VALUES(
'Lar
s',
'
Monsen'
)
TheSQLst
atementabov
ewoul
dinser
tanewr
ecor
dint
othe"
Per
sons"t
abl
e.The
"
P_I
d"col
umnwoul
dbeassi
gnedauni
quev
alue.The"
Fir
stName"col
umnwoul
d
besett
o"Lar
s"andt
he"
Last
Name"col
umnwoul
dbesett
o"Monsen"
.
ALTER
Af
tery
oucr
eat
eat
abl
e,y
ou’
renotnecessar
il
yst
uckwi
tht
hatexactt
abl
efor
ever
.As
BASI
CSTRUCTUREQUERYLANGUAGE RI FTVALLEYUNI
VERSI
TYNEKEMTETVET
COLLAGE2024 FI
RSTEDITED
I
NSTRUCTORBYMR:-
GEMECHUAPAGE20
y
ouuset
het
abl
e,y
oumaydi
scov
ert
hati
t’
snotev
ery
thi
ngy
ouneedi
ttobe.Youcan
uset
heALTERTABLEcommandt
ochanget
het
abl
ebyaddi
ng,
changi
ng,
ordel
eti
nga
col
umni
nthet
abl
e.I
naddi
ti
ont
otabl
es,
youcanal
soALTERcol
umnsanddomai
ns.To
cr
eat
eaPRI
MARYKEY const
rai
ntont
he"
ID"col
umnwhenCUSTOMERSt
abl
e
abov
eal
readyexi
sts,uset
hef
oll
owi
ngSQLsy
ntax
:
ALTERTABLECUSTOMERADDPRI
MARYKEY(
ID)
;
NOTE:I
fyouuset
heALTERTABLEst
atementt
oaddapr
imar
ykey
,thepr
imar
ykey
col
umn(
s)mustal
readyhav
ebeendecl
aredt
onotcont
ainNULLv
alues(
whent
het
abl
e
wasf
ir
stcr
eat
ed)
.
I
fORDERSt
abl
ehasal
readybeencr
eat
ed,
andt
hef
orei
gnkeyhasnoty
etbeenset
,use
t
hesy
ntaxf
orspeci
fyi
ngaf
orei
gnkeybyal
ter
ingat
abl
e.ALTERTABLEORDERS ADD
FOREI
GNKEY(
Cust
omer
_ID)REFERENCESCUSTOMERS(
ID)
;
To cr
eat
e a PRI
MARY KEY const
rai
nton t
he "
ID"and "
NAMES"col
umns when
CUSTOMERSt
abl
eal
readyexi
sts,
uset
hef
oll
owi
ngSQLsy
ntax:
ALTERTABLECUSTOMERSADDCONSTRAI
NTPK_
CUSTI
DPRI
MARYKEY(
ID,
NAME)
;
I
fORDERSt
abl
ehasal
readybeencr
eat
ed,
andt
hef
orei
gnkeyhasnoty
etbeenset
,use
t
hesy
ntaxf
orspeci
fyi
ngaf
orei
gnkeybyal
ter
ingat
abl
e.
ALTERTABLEORDERSADDFOREI
GN KEY(
Cust
omer
_ID)REFERENCESCUSTOMERS
(
ID)
;
I
fCUSTOMERSt
abl
ehasal
readybeencr
eat
ed,
thent
oaddaCHECKconst
rai
ntt
o AGE
col
umn,
youwoul
dwr
it
east
atementsi
mil
art
othef
oll
owi
ng:
ALTERTABLECUSTOMERSADDCONSTRAI
NTmy
CheckConst
rai
ntCHECK(
AGE>=18)
;
SQLUNI
QUEConst
rai
ntonALTERTABLE
Tocr
eat
eaUNI
QUEconst
rai
ntont
he"
P_I
d"col
umnwhent
het
abl
eisal
readycr
eat
ed,
BASI
CSTRUCTUREQUERYLANGUAGE RI FTVALLEYUNI
VERSI
TYNEKEMTETVET
COLLAGE2024 FI
RSTEDITED
I
NSTRUCTORBYMR:-
GEMECHUAPAGE21
uset
hef
oll
owi
ngSQL:
ALTERTABLEPer
sonsADDUNI
QUE(
P_I
d)
Toal
l
ownami
ngofaUNI
QUEconst
rai
nt,
andf
ordef
ini
ngaUNI
QUEconst
rai
nt
onmul
ti
plecol
umns,
uset
hef
oll
owi
ngSQLsy
ntax
:
ALTERTABLEPersonsADD CONSTRAI
NTuc_
Per
sonI
D UNI
QUE
(P_
Id,
Last
Name)
SQLDEFAULTConst
rai
ntonCREATETABLE
Tocr
eat
eaDEFAULTconst
rai
ntont
he"
Cit
y"col
umnwhent
het
abl
eisal
ready
cr
eat
ed,
uset
hef
oll
owi
ngSQL:
ALTERTABLEPer
sons
ALTERCOLUMNCi
tySETDEFAULT'
SANDNES'
DROP
Remov
ingat
abl
efr
om adat
abaseschemai
seasy
.JustuseaDROPTABLE
<t
abl
ename>command.Youer
aseal
lthet
abl
e’
sdat
aaswel
last
hemet
adat
athat
def
inest
het
abl
eint
hedat
adi
cti
onar
y.I
t’
sal
mostasi
fthet
abl
enev
erexi
sted.EgDr
op
t
abl
eCust
omer
s.
Del
etePr
imar
yKey
:-
Youcancl
eart
hepr
imar
ykeyconst
rai
ntsf
rom t
het
abl
e,Use
Sy
ntax:
ALTERTABLECUSTOMERSDROPPRI
MARYKEYPK_
CUSTI
D;
Todr
opaFOREI
GNKEYconst
rai
nt,
uset
hef
oll
owi
ngSQL:
BASI
CSTRUCTUREQUERYLANGUAGE RI FTVALLEYUNI
VERSI
TYNEKEMTETVET
COLLAGE2024 FI
RSTEDITED
I
NSTRUCTORBYMR:-
GEMECHUAPAGE22
ALTERTABLEORDERSDROPFOREI
GNKEYCust
omer
_ID;
Todr
opaUNI
QUEconst
rai
nt,
uset
hef
oll
owi
ngSQL:
ALTERTABLEPer
sonsDROPCONSTRAI
NTuc_
Per
sonI
D
Todr
opaDEFAULTconst
rai
nt,
uset
hef
oll
owi
ngSQL:
ALTERTABLEPer
sons
ALTERCOLUMNCi
tyDROPDEFAULT
DROPorDELETEDat
abase
TheSQLDROPDATABASEst
atementi
susedt
odr
opanexi
sti
ngdat
abasei
nSQL
schema.
Basi
csy
ntaxofDROPDATABASEst
atementi
sasf
oll
ows:
DROPDATABASEDat
abaseName;
Exampl
e:
I
fyouwantt
odel
eteanexi
sti
ngdat
abase<t
est
DB>,
thenDROPDATABASEst
atement
woul
dbeasf
oll
ows:Dr
opdat
abaset
est
DB
Thespor
ti
nggoodsst
oredat
abasecont
ainsf
ourt
abl
es:
CUSTOMER,
PRODUCT,
I
NVOI
CE,
andI
NVOI
CE_
LINE.
Exer
ciseWr
it
etheSQLDDLcommandt
hati
mpl
ement
sthedat
abase.Namet
he
dat
abaseSpor
ti
ng_
goods.
Tabl
e Col
umn Dat
aty
pe Const
rai
nt
BASI
CSTRUCTUREQUERYLANGUAGE RI FTVALLEYUNI
VERSI
TYNEKEMTETVET
COLLAGE2024 FI
RSTEDITED
I
NSTRUCTORBYMR:-
GEMECHUAPAGE23
CUSTOMER Cust
omer
ID I
NTEGER Pr
imar
ykey
Fi
rst
Name CHARACTER(
15)
Last
Name CHARACTER(
20) NOTNULL
St
reet CHARACTER(
25)
Ci
ty CHARACTER(
20)
St
ate CHARACTER(
2)
Zi
pcode I
NTEGER
Phone CHARACTER(
13)
PRODUCT Pr
oduct
ID I
NTEGER Pr
imar
ykey
Name CHARACTER(
25)
Descr
ipt
ion CHARACTER(
30)
Cat
egor
y CHARACTER(
15)
Vendor
ID I
NTEGER
Vendor
Name CHARACTER(
30)
I
NVOI
CE I
nvoi
ceNumber I
NTEGER Pr
imar
ykey
Cust
omer
ID I
NTEGER
BASI
CSTRUCTUREQUERYLANGUAGE RI FTVALLEYUNI
VERSI
TYNEKEMTETVET
COLLAGE2024 FI
RSTEDITED
I
NSTRUCTORBYMR:-
GEMECHUAPAGE24
I
nvoi
ceDat
e DATE
I
NVOI
CE_
LINE Li
neNumber I
NTEGER Pr
imar
ykey
I
nvoi
ceNumber I
nteger
Pr
oduct
ID I
NTEGER
Quant
it
y I
NTEGER
Sal
ePr
ice NUMERI
C(9,
2)
Not
icet
hatsomeoft
hecol
umnsi
ntheabov
eTabl
econt
aint
heconst
rai
ntpr
imar
ykey
andNOTNULL.Thesecol
umnsar
eei
thert
hepr
imar
ykey
soft
hei
rrespect
ivet
abl
esor
col
umnst
haty
oudeci
demustcont
ainav
alue.At
abl
e’
spr
imar
ykeymustuni
quel
y
i
dent
if
yeachr
ow.Todot
hat
,thepr
imar
ykeymustcont
ainanonnul
lval
uei
nev
eryr
ow.
Thet
abl
esr
elat
etoeachot
hert
hrought
hecol
umnst
hatt
heyhav
eincommon.
Thef
oll
owi
ngl
i
stdescr
ibest
heser
elat
ionshi
ps.
TheCUSTOMER t
abl
ebear
saone-
to-
manyr
elat
ionshi
ptot
heI
NVOI
CEt
abl
e.One
cust
omercanmakemul
ti
plepur
chases,gener
ati
ngmul
ti
plei
nvoi
ces.Eachi
nvoi
ce,
howev
er,
deal
swi
thoneandonl
yonecust
omer
.
TheI
NVOI
CEt
abl
ebear
saone-
to-
manyr
elat
ionshi
ptot
heI
NVOI
CE_
LINEt
abl
e.An
i
nvoi
cemayhav
emul
ti
plel
i
nes,
buteachl
i
neappear
sononeandonl
yonei
nvoi
ce.
ThePRODUCTt
abl
eal
sobear
saone-
to-
manyr
elat
ionshi
ptot
heI
NVOI
CE_
LINEt
abl
e.A
pr
oductmayappearonmor
ethanonel
i
neononeormor
einv
oices.Eachl
i
ne,
howev
er,
deal
swi
thone,
andonl
yonepr
oduct
.
TheCUSTOMERt
abl
eli
nkst
otheI
NVOI
CEt
abl
ebyt
hecommonCust
omer
IDcol
umn.
TheI
NVOI
CEt
abl
eli
nkst
otheI
NVOI
CE_
LINEt
abl
ebyt
hecommonI
nvoi
ceNumber
BASI
CSTRUCTUREQUERYLANGUAGE RI FTVALLEYUNI
VERSI
TYNEKEMTETVET
COLLAGE2024 FI
RSTEDITED
I
NSTRUCTORBYMR:-
GEMECHUAPAGE25
col
umn.ThePRODUCTt
abl
eli
nkst
otheI
NVOI
CE_
LINEt
abl
ebyt
hecommonPr
oduct
ID
col
umn.Thesel
i
nksar
ewhatmakest
hisdat
abasear
elat
ional
dat
abase.
BASI
CSTRUCTUREQUERYLANGUAGE RI FTVALLEYUNI
VERSI
TYNEKEMTETVET
COLLAGE2024 FI
RSTEDITED
I
NSTRUCTORBYMR:-
GEMECHUAPAGE26