DatabaseManagementSystems,R. Ramakrishnan andJ. Gehrke 1
SchemaRefinementand NormalForms
Chapter15
DatabaseManagementSystems,R. Ramakrishnan andJ. Gehrke 2
TheEvilsofRedundancy
❖ Redundancy isattherootofseveralproblems
associatedwithrelationalschemas:
– redundantstorage,insert/delete/updateanomalies
❖ Integrityconstraints,inparticular functional
dependencies,canbeusedtoidentifyschemaswith suchproblemsandtosuggestrefinements.
❖ Mainrefinementtechnique:decomposition (replacing
ABCDwith,say,ABandBCD,orACDandABD).
❖ Decompositionshouldbeusedjudiciously:
– Istherereasontodecomposearelation? – Whatproblems(ifany)doesthedecompositioncause?
DatabaseManagementSystems,R. Ramakrishnan andJ. Gehrke 3
FunctionalDependencies(FDs)
❖ Afunctionaldependency XYholdsoverrelationR
if,foreveryallowableinstancer ofR:
– t1r,t2r,(t1)=(t2)implies(t1)=(t2) – i.e.,giventwo tuples inr,iftheXvaluesagree,thentheY
valuesmustalsoagree.(XandYaresets ofattributes.)
❖ AnFDisastatementaboutall allowablerelations.
– Mustbeidentifiedbasedonsemanticsofapplication. – Givensomeallowableinstancer1 ofR,wecancheckifit
violatessomeFDf,butwecannottelliff holdsoverR!
❖ KisacandidatekeyforRmeansthatKR
– However,KRdoesnotrequireKtobeminimal!
→
∈ ∈ π X
π X π Y πY →
→
DatabaseManagementSystems,R. Ramakrishnan andJ. Gehrke 4
Example:ConstraintsonEntitySet
❖ ConsiderrelationobtainedfromHourly_Emps:
– Hourly_Emps (ssn,name,lot,rating, hrly_wages,hrs_worked)
❖ Notation:Wewilldenotethisrelationschemaby
listingtheattributes:SNLRWH
– Thisisreallytheset ofattributes{S,N,L,R,W,H}. – Sometimes,wewillrefertoallattributesofarelationby
usingtherelationname.(e.g.,Hourly_Emps forSNLRWH)
❖ Some FDs onHourly_Emps:
– ssn isthekey:SSNLRWH – rating determines hrly_wages:RW
→ →
DatabaseManagementSystems,R. Ramakrishnan andJ. Gehrke 5
Example(Contd.)
❖ ProblemsduetoRW: – Updateanomaly:Can
wechangeWinjust the1st tuple ofSNLRWH?
– Insertionanomaly:Whatifwe
wanttoinsertanemployee anddon’tknowthehourly wageforhisrating?
– Deletionanomaly:Ifwedelete
allemployeeswithrating5, welosetheinformationabout thewageforrating5!
→
S N L R W H 123-22-3666 Attishoo 48 8 10 40 231-31-5368 Smiley 22 8 10 30 131-24-3650 Smethurst 35 5 7 30 434-26-3751 Guldu 35 5 7 32 612-67-4134 Madayan 35 8 10 40 S N L R H 123-22-3666 Attishoo 48 8 40 231-31-5368 Smiley 22 8 30 131-24-3650 Smethurst 35 5 30 434-26-3751 Guldu 35 5 32 612-67-4134 Madayan 35 8 40 R W 8 10 5 7
Hourly_Emps2 Wages
DatabaseManagementSystems,R. Ramakrishnan andJ. Gehrke 6
RefininganERDiagram
❖ 1stdiagramtranslated:
Workers(S,N,L,D,S) Departments(D,M,B)
– Lotsassociatedwithworkers.
❖ Supposeallworkersina
deptareassignedthesame lot:DL
❖ Redundancy;fixedby:
Workers2(S,N,D,S) Dept_Lots(D,L)
❖ Canfine-tunethis:
Workers2(S,N,D,S) Departments(D,M,B,L)
→
lot dname budget did since name Works_In Departments Employees ssn lot dname budget did since name Works_In Departments Employees ssn