DBMS 3-Unit

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 15

DBMS KINA-( Unft-)

1 MaK.
what ia Deonpoi ton
Decomposi#oo DEMe s used -to break a relaticn Tnto
PositOn:
Nornal Form.
muitiple elatioos te brirgt 1nto an approp îate
heips to reduce vedundancd, anomal?es and inconsistencie s
t
then ft nay lead tocthes
elation fs mot ppPelu decomposed
Poblens fke fofomatlorn loss
Detine unjon operator 5 example ?
Ans UNION lu):
Tnstance contanog all tuples that tcn in e?then
returns a relaticn fstånceS o both
elatfonal
eiatin înstance R Y
S
S.name Ratioq| aqe s-1D|5-Agene rateng age
3s
Dustin |45
31 Rusty
S8 Rusty 35
44
fumpy S
3S
puppy S8 35
6-1DS-Dame
Dustin
3t
Rusty 35
44 Cumpy 3S
S8
pupry 3S

Deine nibrmatgatn?
yommal igation: Nemalizattoo 1s a prcess oB manânig in9 nedundaneyroma
Ans nelation ba a set of elations
may cause tnsevtion, de le tiong up date nomalies
+Redundancy in a nelation
60.it helps to heduce nedundancy in nelations
cohat are he types Aggregate tuneto ? petomealeulatfons cn
Agqregate-funelons : An Aggegatee-functfon in s6L
ans and oetums a single Val ue
malttpe Values
Ag7eqate -unetiens::
Tyees cf Aqgoeqate.
MINC)
COUnT() S8L
MA XC)
-function

AvG)
s)
cohat s Nested aueyy?
that has anothex
S Neséed Sueny: The nes ted quey is a tte
embedded hn it
quey
athe enbedded quey s calied a subquer Y
# Consists of tnN, woT IN,exST, NOT ExIST operators

SMARks
Descybe a sQLQuey wfta example ?
Ans Tthe basie tomD a SQL query is as -follos:
Select Lst
sCLCCT (DisTINC
FROM fromist
dHCRE qualification
must have
columo to be vetained in the
SELECT clause Whicbspec?fies the
nesut
he table
FROM clause which specfes acDSS Producl of
mentioned in FRDM
NHERE Specifes selectioo condft?on onthe abtes
cËause
DiSTINCT - Can be usedto relun only unig ue Values .
ex: student
S-name

Ram 18
2 Ravi
3
Raju
Ram
Select DISTINCT S.name omSdent:

output:’
Ram
Ray?
Raju
wnite about databaye anoma ies ?

Ans A database Anomaly is a inconsistencH eo -the data esulting-trom


oper atlon ike update, delete and nsetfoo .
Redundant storngei some to-fovrn aion whichis séovedepeateciy
Cepdate Anonalles: when we update sone mDs iy-the table , and
1f 4 leads to -the ?ncongstency of the table then the anomal
Insevéion nomalles : theseis a meo rOoiosevted inthe table
and t Creates -the inconsistency the table
Deletlon Anonales; I we delete Some mos from the table and
ang othe fo-fornation o data whfch ts neqrecd is also deleted
om the daLabase
n¡mmalize-the tables
TOvemoue this ty pe of anomaies oe coitl
Split the table o join the ta ble

Ans nVL Nalues


A NULL Value in a elaional database ís used when the Value in
a colurmo is unknowon 07 ss g
Bero Vale
>A ULL Value ts meither a
eipty stsog mor a
he tem NULL in S6L s used to Specit that a datvalue
does mot eist o the database
ue muSt use is OTOULL "opevatos to check ifa
Value s
Is AULL - to test empE ualue s
6pecífes that a column should always accept an
explicit values of the quen datatype
SyntaX -for IS NOLL:’ Select columnname fom tablemame
HeRe column.mme is nULL
ex Stu dent
S.D S-name s.age s emal
ABC ABe@ gmail.com
30
R@qmau.com
3
Raju@ qmah.com
4. Rav?
Sel ect Xfrom studenl wtleRE S emiu is ULL ;
S.iD S-name S_ema

Rav? 8
HntaY fo 1s AOT wULiy select columnname from tablename
WHeRE Colum. name s OT ULL;
SX* Select -x -from stUden HERE 5.emål ?s OT ULL;
olp:S.ID S. name S.age S-emal
ABC ABC@gmn£l.com
30
Y3@qm£il.com
9

4)
Raju Rajuqmai.co
are Ika bakic SQL Commanda wits enample.
Ans Basic SeL Cornmandsi’
de-fne a
C}CRENTC TAP LE: The ceatetable statemeots used to
mEw table to Create the se udente xelatioo e can use the

toncutg staterments

Ex: CREATE TABLE Students (std cha (26,mame char(30), loqto


charl20), inteqe qpa Ren);
C) INseRT: Tuples are inseted the InERT command and we
Can USe Inset to osert a Stngle -tuple fnto -the studenls table a5
follows
TNseRT fnto students sid,mame, toqio,ageqpa)
VALUES( 53688, 'smith', 'smitHOCse', 18,3- 2),536S1,
Jack',sackcse' 19, 8.5);
Commond.
Cin) DeLETE we can delete tuples qstnq the DelCTE
De can delete all students uples with mame = Smith -this
Conand.
DeLeTe FROM stidenots HeRE nome = smith';
CiN) UpDATE: We can modHy-the Values in the the

OPDATe Comand

UpDATE students SeT age aqetl,3Pa= apa-l


WHCRe Sid= B3689;
name
loqtn qe gPa
53689 Tack Tackacse 0 4.5
5)
List out he ules Avma tyong Axloms ?
Ans Amstrong Aviemns i hen ap plled
the Avmsévong Axioms are a set of Tules,-that
ly,qenerates a closure of functional dependencies
7epeated
Tf F fs a'set of function al dependencies then -the closuve o4 F
denoted as Ft;,s the Sel of all -functBonal dependenes loqicalls
mpied by F
Rules o4 Armsiroq ioms :’
(ii Axioms of Reflex+vity* : f4 AAisis a set of attibutes and B is O
Subset o4 A, then hoids B. If BeA then A>B.This propety is
4fvial property
Cm Axibms o4 Augmentation: T AB holds&y 9s the attibute
Set, then AY y By aiso holds. That Îs add fog attib utes to
dependencies, does not change -the basic dependencfes. i4 AB,
then Ac Bc-oy
any e
Cm) axfoms of trans?ity: 6ame asthe tans?tive rule o
Algebsa,f A-’B ttotds añd Bc hol ds ,then A calso holds
A eis called Afunctionatly wh Pch deteymnes B.
K y and ’ then xyz.
5MARKs
Explain Funetonal depeudey cy wfi elosure and Abute
cloure.
Ans Fun ctfonal dep endency: functional dep endency is a elatio)
bet ween the attbutes o{ a table related to eachother It helPS
to maintan the
uality of the data in -the database
Funceooal dependency
?s vepresented by
Rs
y
denoted
by
closue of a Set af fos :
The set of all F.ps fmplied by auenD set o Fof FDs ?s called
the clOSure o4 F, denoted by Ft
The ouOSinq three mules caled
Amstroogs Axioms can be
applfed vepeated ly to înfes all FOs.
x,yzare set o4 attibutes ove a relation schema R
Redtextuity: 4 x>y
Augmentation; Itx , hen X7-’ Yz oy any z (pareial
dependenep
Thansitiky: T! x’} and Y-’z then X’ 2
union
Decomposition: 4 X - then X’Y and X-’ z
xt ofthespecl to F, which
Attibute closure!he Att?bute closune
attributes A such that XyA Can be tbfeed usng
is the sel of
the Armstrongs nxiorms: the tthibute closune of a set X of
The Algoithn-o
eompatbg
attibutes 9s shoory belo:
closune=X 3
epeat untilhene is no ehange:? in F Such that Ucclosue,
f theYe 96 an FO Uy
then set cosure =closUre U V .

Fxplain Aqgre gak opevatova wfh erample.


mo Aqqreqate operators: fn AAgegate opeators n 6L pertomS
a sfnqle Value
Calculations on multiple ualues and return
Value6 ohen t pefoms
An Igregote operators ignoves-fenc tton
Calculatlons except for the count
many aggegate functions thal includo avg)
SQ Povides
Sum(,MiNC) , nMAXCetc
|Count(,
EX? ¬Mp. DATA Table
Name Dep& salany
Ram Mantetisg
Heny produclion16,oDO
3 Disha RD 46,00
Helen 84,b00
Meera

Afsha mantding
Productfo 64,000
Bhuvan Prpducton 60,000
Ha REr D 60)000
Pseeth?
Mank Manteling NULL

production 66, D0O


CoUNT(): coUNT() netuns the total no.ofbos-trpma database
table that matches the cdefined citeia n he sa! quey
Syntax: covNT (*) oR
CoUNT (coLUMNNAMe)
ex SelcCT cooNT (salar) From eMp- DATA3
SUM0:The SumC)functiontakes -the name f the Columo as an
arqument nd retems the 6um of the al non-nULL Values în
onts onty în mmeric felds
the columo. It wrts
ex: select SoM (salay) Fron eMP bATA 3
colum as an
AvGi(The AVG( fncton uses t he name bf the
aqument and netuMS the avey age alues 0f al the mon nULL
tie lds
values in the colem it cooks only -fo nUmerie
ex: select ANG6alav) From ¬mp DATA,
olp: I444.444 columo aS an
MIC)unction tares the mame of the, colum
MiNC);
etums the Value Present in-the
nïmum
|argument and
Fom ¬Me DATA ;
ex: select MIN (salar)
column aS Q)
MAXc): MAx)-function tares the name ofthe
pyesentnthe column
arqurnent and eturns the maimum Value
x: select AX (6alany) Fom eMP_DATA;
elp: 84ID00 the
SQL is used to
GIROUP BY: The GIROUP BY 6tatements io
some -functions
ddentical data fnto qrouP$ of-th-the help of
select AMe, 6UM(EolumN-NAMc) fRoMTAB LE-OAME
S4ntaX ?
GIROUP BY CoLUMNAme;
clause s use d n b8Ms to-fetch the dala/
HANING The HAVNG to ~the qiven coneition
accodiog
values from the qroups expain poroblemy aused
Defne Sehema Reftnement and
by snedundauy Schema Re oem ent is a technfque of
Ans Schena Re finemen: database .
the data LO the
aPproach of decomposingtabtes to elminate
T0 is a Vsqst em atic undesrable characlesislics Ifke
data nedundàncy and
anomalles
Roseoton, upda te and cdeletion same data .
Reduniancy means dup licate co pies af t he
Problems causec by Redundancy redundantly , that fs n moethan
same informaton
the sevenal poblems
lead to
clataba Se )Can
lone piace b-this a
’A database Anprmaly Ps an fnconss tency o the data
operatfon iPke an update,delete &e
Pnse,efo
Redundant : seme nfoma on s stored epeatedly
fupdate Anomalies: ohen e update some ws o the tae
and tf tu teads to the fneonsitfency of the table then -this
anomal DcCu$.
|+Insention Aoonalles : T4 thenefs a meo inses ted n he
able and it creates the 4nconeistency n the table
’ Deletfon : 14 we delete som s fom the table
and any othe tfor o data ohich 9s eqinelis
also dele ted hom he database
TO nemoue this tqre of anomalfes oe ol) momalzethe
Split he table on fointhetables.
Explain Ike peva tos En SQL wfln an erampe
4)
UAOAA
follog
DANTER SsATIDA 3. 5x CEPT

Ans
) oNIoN(u): (Rus)
all tuples that occur
netmsa relatioo instance eone.o fostance So
0 efthe nelatfon s t a nce R O

both.
example:
S-NQme S-1DS-amne
S-ID

31
Rusty 35
Rusty
44 |qumy BS
58
Puppy 58 35

Susa S-Name
Katog
Dustin
Rusky 35
3S
Gumpy 35

(i) inTE RSECTrION (Rns) contineng alltapleshat


Retursa relationship fostanee
occun in both R and s
compatible and the
the elatio Rand S must be unton
olthenesut9s defined to be identica) -to schema of R
Schern
S-name
SS

bet coeen tiop t eies and


C) ¬XcePT: Fods be d erfeence
the es t he too o0S that
com pa es belonqs onlytothe
6-name

Dustin 45

Descvi he /e DDL (ata befmitn ugage)


Iti TYn cate
Ans C) CREATE( : defioes each coluon Df -the ta ble uni uely.¬ach column
has mnmee m 0-f hee attibutes a name )datatyre e'siae
Cn) ATERO . AlHe Command s Used to add -the column tothe aheady
Created table
usedto delete a o w even
Ctn) bRoP; Drop Command is
Com ple le table wS
TRUNCATCC): Tuncate Commano is used -to dele te al the
Cv)
table to pemanent
ex: cveate database 6tudent ;
Use student vancha(3),6td.age int);
Create table stud (std. Id int ,6tdname
tnsest
Select *
ioto Stud values ( i,"Ram", 18) ,(a, " Raju", ),(3,shyam", o);
rom Stud;
Std-namel std..age
Ram 18

3
Raju
chya manks int)3
Alter tabie studev add (S
Std-name Std.age S.man ks
Ram
Raju 19
3
shyam
mop AItey table stud dop columo S.manks,
Select * om stud;
Sedicd Std.name
Ram 8
Raju
shyar 20
IOMARKS
fgge ? Explain kos to Pmmplement tigge
what is r
SQL.
feh fis autematicatl
ins Tiggess : n Thigge is a ppcedune oh to he dalabase
tnuercd by the DRMS 9n vespen6e to hanges
andis spectfitd bs the DBA
A database oleha sel of assec faled f93ers is
caled an QcLue databa6e
Pants of oqge databae ohfch
is a chanqe to he
Ca) event: An evenl
actiuates the
aoher the
(6 condieion: Aquery o
aceivaled .
(e) Actéon: A Pocedune -that is executed hen ¬ he tqgeis
activated and 9ls condft fon ?S tnie
could ace?vale a
An Insentidelele, update statement

answes Sel is
Quey 1s ntepreted as tme 4f the
and false fl the que has no answers
nony
acton
JH the condf{loo Pat evaluates - l o t e , the
2
associated fth -the tHgaer Ps Executed
’A Qctlo o can exanine the a S e S {o-the
Hhe condition pant of thet g e
oqgex
’Anfpontant 1s5ue s when the actlon Pat of a
eyect e ?n a nelaton t the 6tatemen that activnted

he tiage hat insets econd oto


fo earnple, a statement
that s used to
st udeot table may acti ate a
maintain ttalistts on hos many students younge than us
ave insented a a tfme by a -tprcal inserl slatement
Cxarmple c tigeS
Create tigge int count Bofore Tnsent bn suden ls /*cvent/
Declane
count Tnt eqe3
heate in count {4en Insent on student X Euent*/
kohen (newiage <i8) / conditfon* /
to each o w
Actfon */
Count;= Count t

The called nc count ?oeement the countes to


each iseted tuple that satistes the condition age <I8

leue) rfqger : te is ffxed only on ce


Statement leuel fon DML
6¬at emnent oespectrve of no.of o OS af ecte d by the.
SLat emen L
These ane defaulEdefault ype of ti9ge .

Roks level tiqge H ts xed to each that is


aftected Dml Command
by
Bxplain Noy mai2atton of th ANE, 2 NE, 3NF, BCAf, 4NE
and NF?
pDcess o-f mnimigfng
Aps Nomalizatiog: Normaligation fs a set of elations.
nelatfon o a
nedundancy nser tion,deletion and
Redundancy ina nel ation may cause
Anomales. soiit helps to educe redundamyin
update
selations
of uidelfnes -that
in pens,om al fom s ave a seiesdatabase s eficfent
helps to ensUne that the design of
data anoales.
ongan?ged and -toe trom
fhst Nomal Fom: Cn)
In lof, e ath
This is the most basie leuel of mommal?gatioo.
value,and eaeh
|able cell should contan only a siogle
cotumo Should haue a unique mame The( P holps to
eliminate dupticate data
ex: Jcontent
COnse
|Prog ammtng
eb HTMLIPHP,ASP
CuSe COntent

|Pognanming
Web HTML
web PHP
web
Asp
Second Nma/ Form (aF): OF elCnbates edurdant data
Attîbute be dependent on -the
nequinihqthat each mon
-key
’This men6 that each solum should be velated to the
key and mot to btoen Colums decty
EX: student Group
RveNam Goep Fee R-no Knoo
Ram lok DBMs
2
Shyam cce I5K 2.
3
Raju ECE l2k 3 DBMS
RNO wame Lag- knon
-P
tw Group fee
Ram lok
Ram p BMS CSE oK
2
Shyam ece IsK
shda Java
3
eaju DBMS ECe I2K
Thod nonal -forn (3F): Foy a elatioo io 30F, it muse be in 9NFand
(o)no mon primne attibute is t ansitfvely dependent on pmme ke
attibute cb) fo any mon tifal functional dependency, key
ethe x is a supen ke o1 A is a Prne Attibute XA,thes
eX; Student Fee
Croup
noame Giroup Croup fee R
Ram CSC
KnOn
lok Lang
DBMS
3 shyarg ECe ece
Sava
DBMS
BcNF: BcNF i5 the advanced vension of 30F
Sectlon subfect FacuilqTime section Faculty Time
A Cornp Sudhakas 8:00 A Sudhaka 8:00
A
B
phy 9:0D A
Raju 9:00
comp am to:00 B R am I0DO

cormp shyam shyam


Subject Facuty
comp Sudhara
phy Raja
comp Ram
comp chyam
founth NOmal Fom (4NF): fo a nelatioo îo 4+E, l mus{ satisfiéc
BcnF and no mutivalued depende ncy
Stutdeot stdcouse std-Hobby
St. id Course Hobby Stdid Couse Hobby
24
compDancinq
maths
comp
maths |oarcing
34 chem
Daneinq 34 chen 34
44 BfO cicket 14 4 Danci
ietetng
ehy Hocke y |ehey 39
Hockey
Fifth momal fon(5N): for a selatiopio SNF, t must
6atisfies
4NF and cdoes mot contn any jon
dependencies
Cx:Subject Lectunes Ser
Anshika
subject Lecturer
comp comp
Comp Tohn
maths Jobn
cornp
mathS
maths Akash 2 2.
maths
chem Praveen chem

Subfect Se Lectues sem


Comp Anshika
Comp Tohn
maths Jobn 2
maths Acash
Chern Praveen
tron ?
a) Explotn lose gofn de composiDependan y vo)?
b) Emmarate Multt -vaued
s Lossless foo decomposition: lossless foo decor.posrtfon in DBMs
anelaefon Rhas to un devgo decomposftfon in t0o relatfons RI6 R2
|the neiation R ohich fs o5igînal nelaton îs obtained
+In loss(e ss foin decomposrefon,a elation ?s decom posed into
ued
s preser
foal data afteo
nelations Henceeata
data
R4 RS ensued thal the ofqinl
|neconstruct Pon should be sa me
’Anothes Mame to loss te ss fo ln decomposfeîon fs
non-addïe foin decompostton.
fo lossless 6tn deompoftton, we 5e[ect atommon attibute
The cReenlato seledlog the same Ps that tt hasto bea
candida te he
forefgn key n Supertey n etthe aelations Ri,R2
both.
In addft Pon Ca)the unon o-f the sub elot fons elafool
velation should be cont aânina
al the att butes hat may
Pesent In the eatg Enal relaton R hich qot decomposec
C6) The ntersectfon of subrel atfons elatonl& elationa is not
atowed to be nw le Ts mecessao t h Subelati on tO
contain a common attfbute
nelation RA,B,cThe netation R
EX: consfde the
has attaibules
-tolioustnq
AyBic. The elatîon R decoposed înto a ne lattons
Rjand R9 oith common attibute B.
R (AB) and Ra = C8,c) Also, t ts mpotantto emembe that
unhue Lf theve fs
the vatue pyesent fo the column B should be
mot posstble -fon lossless
any psesence of aduplicate Value, Pt 1s
|oig decompositloo-to tke place
ABC
R
2
3

R=FAB,c? RyCAre)
Multf-ualuec Depende ncy MvD): muli-valued depende ncy
Ctates that tuo todepeñdent data vantables eand en a
table can be dependert bo thrd vartable Anespectvey
MVD bcctuns ohen too atEbutes io a tabie anende pen dent O4
eachother but ae dependent on tHd ynfable
>stoce, mD consists of a nmum V a ab ies to be
dependent on -thid vatabe. sojthe rinimu amount of vaniableg
neqied is 2)
Repesentatior f muD is B,C A
Mup a b a fs mult alued de penden t on B
not
mVD ex+st -these follofo g condftions0
Say Relaton
H any Attibute Hutfpledependeey onBie
R.foy all Pairs of datavalues in
DRi D R a
ndthe
Such that the elation R,Ca)+ Ra (a)exists,
o Rg O RA exfsts a table such that
elation blus
RCa) Rca) R3a)= R4 (a)
can that nultfv alue d
A (b)- R3 (6); Ralb= R4 Cb) then Ae
exist ohich means, Po he Dhs RR2, R3 E R
dependeney
ex: Dame COUSe
Hobby
Rabul
Rahul Pyehon |painttng
music

Rahul music
Rahu)
Veriffcatfon:
Pqthon
patnibg
Condtion 4 MVO RCa) = Ry Ca)- Rg(a) R4 (a) = Rahl
Condition muD R(b) = Rglb)- c++ and Ralb) R4 Cb)e Pyhon
Cordfelon3 mVD
Rilc)- RyCc) and Ral) e Rzlc)emusic
Dame - ’ - cour Se and
palntn
ame
--Hobb

You might also like