Вы находитесь на странице: 1из 6

6/2/2015

NormalFormDefinitions&Examples

IST210
OrganizationofData
NormalFormDefinitions&Examples
FromCodd&Date

1NFArelationRisinfirstnormalform(1NF)ifandonlyifall
underlyingdomainscontainatomicvaluesonly
Example:1NFbutnot2NF
FIRST(supplier_no,status,city,part_no,quantity)

FunctionalDependencies:
(supplier_no,part_no)quantity
(supplier_no)status
(supplier_no)city
citystatus(Supplier'sstatusisdeterminedbylocation)

Comments:
Nonkeyattributesarenotmutuallyindependent(citystatus).
Nonkeyattributesarenotfullyfunctionallydependentontheprimarykey(i.e.,statusandcityare
dependentonjustpartofthekey,namelysupplier_no).

Anomalies:
INSERT:Wecannotenterthefactthatagivensupplierislocatedinagivencityuntilthatsupplier
suppliesatleastonepart(otherwise,wewouldhavetoenteranullvalueforacolumnparticipatinginthe
primarykeyCaviolationofthedefinitionofarelation).
DELETE:Ifwedeletethelast(only)rowforagivensupplier,welosetheinformationthatthesupplier
islocatedinaparticularcity.
UPDATE:Thecityvalueappearsmanytimesforthesamesupplier.Thiscanleadtoinconsistencyor
theneedtochangemanyvaluesofcityifasuppliermoves.

Decomposition(into2NF):
SECOND(supplier_no,status,city)
http://www2.yk.psu.edu/~lxn/IST_210/normal_form_definitions.html

1/6

6/2/2015

NormalFormDefinitions&Examples

SUPPLIER_PART(supplier_no,part_no,quantity)

2NFArelationRisinsecondnormalform(2NF)ifandonlyifit
isin1NFandeverynonkeyattributeisfullydependentonthe
primarykey
Example(2NFbutnot3NF):
SECOND(supplier_no,status,city)

FunctionalDependencies:
supplier_nostatus
supplier_nocity
citystatus

Comments:
Lacksmutualindependenceamongnonkeyattributes.
Mutualdependenceisreflectedinthetransitivedependencies:supplier_nocity,citystatus.

Anomalies:
INSERT:Wecannotrecordthataparticularcityhasaparticularstatusuntilwehaveasupplierinthat
city.
DELETE:Ifwedeleteasupplierwhichhappenstobethelastrowforagivencityvalue,welosethe
factthatthecityhasthegivenstatus.
UPDATE:Thestatusforagivencityoccursmanytimes,thereforeleadingtomultipleupdatesand
possiblelossofconsistency.

Decomposition(into3NF):
SUPPLIER_CITY(supplier_no,city)
CITY_STATUS(city,status)

3NFArelationRisinthirdnormalform(3NF)ifandonlyifitis
in2NFandeverynonkeyattributeisnontransitivelydependent
http://www2.yk.psu.edu/~lxn/IST_210/normal_form_definitions.html

2/6

6/2/2015

NormalFormDefinitions&Examples

ontheprimarykey.AnattributeCistransitivelydependenton
attributeAifthereexistsanattributeBsuchthat:ABandB
C.Notethat3NFisconcernedwithtransitivedependencieswhich
donotinvolvecandidatekeys.A3NFrelationwithmorethanone
candidatekeywillclearlyhavetransitivedependenciesofthe
form:primary_keyother_candidate_keyany_non
key_column
Analternative(andequivalent)definitionforrelationswithjustonecandidatekey
is:

ArelationRhavingjustonecandidatekeyisinthirdnormal
form(3NF)ifandonlyifthenonkeyattributesofR(ifany)are:
1)mutuallyindependent,and2)fullydependentontheprimary
keyofR.Anonkeyattributeisanycolumnwhichisnotpartof
theprimarykey.Twoormoreattributesaremutually
independentifnoneoftheattributesisfunctionallydependenton
anyoftheothers.AttributeYisfullyfunctionallydependenton
attributeXifXY,butYisnotfunctionallydependentonany
propersubsetofthe(possiblycomposite)attributeX
Forrelationswithjustonecandidatekey,thisisequivalenttothesimpler:

ArelationRhavingjustonecandidatekeyisinthirdnormal
form(3NF)ifandonlyifnononkeycolumn(orgroupof
columns)determinesanothernonkeycolumn(orgroupof
columns)
Example(3NFbutnotBCNF):
SUPPLIER_PART(supplier_no,supplier_name,part_no,quantity)

FunctionalDependencies:
Weassumethatsupplier_name'sarealwaysuniquetoeachsupplier.Thuswehavetwocandidatekeys:
(supplier_no,part_no)and(supplier_name,part_no)
Thuswehavethefollowingdependencies:
http://www2.yk.psu.edu/~lxn/IST_210/normal_form_definitions.html

3/6

6/2/2015

NormalFormDefinitions&Examples

(supplier_no,part_no)quantity
(supplier_no,part_no)supplier_name
(supplier_name,part_no)quantity
(supplier_name,part_no)supplier_no
supplier_namesupplier_no
supplier_nosupplier_name

Comments:
Althoughsupplier_namesupplier_no(andviceversa),supplier_noisnotanonkeycolumnitis
partoftheprimarykey!Hencethisrelationtechnicallysatisfiesthedefinition(s)of3NF(andlikewise
2NF,againbecausesupplier_noisnotanonkeycolumn).

Anomalies:
INSERT:Wecannotrecordthenameofasupplieruntilthatsuppliersuppliesatleastonepart.
DELETE:Ifasuppliertemporarilystopssupplyingandwedeletethelastrowforthatsupplier,welose
thesupplier'sname.
UPDATE:Ifasupplierchangesname,thatchangewillhavetobemadetomultiplerows(wasting
resourcesandriskinglossofconsistency).

Decomposition(intoBCNF):
SUPPLIER_ID(supplier_no,supplier_name)
SUPPLIER_PARTS(supplier_no,part_no,quantity)

BCNFArelationRisinBoyceCoddnormalform(BCNF)if
andonlyifeverydeterminantisacandidatekey
ThedefinitionofBCNFaddressescertain(ratherunlikely)situationswhich3NFdoesnothandle.The
characteristicsofarelationwhichdistinguish3NFfromBCNFaregivenbelow.Sinceitissounlikely
thatarelationwouldhavethesecharacteristics,inpracticalreallifedesignitisusuallythecasethat
relationsin3NFarealsoinBCNF.Thusmanyauthorsmakea"fuzzy"distinctionbetween3NFand
BCNFwhenitcomestogivingadviceon"howfar"tonormalizeadesign.Sincerelationsin3NFbutnot
inBCNFareslightlyunusual,itisabitmoredifficulttocomeupwithmeaningfulexamples.Tobe
precise,thedefinitionof3NFdoesnotdealwitharelationthat:
1. hasmultiplecandidatekeys,where

http://www2.yk.psu.edu/~lxn/IST_210/normal_form_definitions.html

4/6

6/2/2015

NormalFormDefinitions&Examples

2. thosecandidatekeysarecomposite,and
3. thecandidatekeysoverlap(i.e.,haveatleastonecommonattribute)

Example:
Anexampleofarelationin3NFbutnotinBCNF(andexhibitingthethreepropertieslisted)wasgiven
aboveinthediscussionof3NF.ThefollowingrelationisinBCNF(andalsoin3NF):
SUPPLIERS(supplier_no,supplier_name,city,zip)
Weassumethateachsupplierhasauniquesupplier_name,sothatsupplier_noandsupplier_nameare
bothcandidatekeys.

FunctionalDependencies:
supplier_nocity
supplier_nozip
supplier_nosupplier_name
supplier_namecity
supplier_namezip
supplier_namesupplier_no

Comments:
TherelationisinBCNFsincebothdeterminants(supplier_noandsupplier_name)areunique(i.e.,are
candidatekeys).
Therelationisalsoin3NFsinceeventhoughthenonprimarykeycolumnsupplier_namedeterminesthe
nonkeycolumnscityandzip,supplier_nameisacandidatekey.Transitivedependenciesinvolvinga
second(orthird,fourth,etc.)candidatekeyinadditiontotheprimarykeydonotviolate3NF.
NotethatevenrelationsinBCNFcanhaveanomalies.

Anomalies:
INSERT:Wecannotrecordthecityforasupplier_nowithoutalsoknowingthesupplier_name
DELETE:Ifwedeletetherowforagivensupplier_name,welosetheinformationthatthesupplier_no
isassociatedwithagivencity.
UPDATE:Sincesupplier_nameisacandidatekey(unique),therearenone.

Decomposition:
http://www2.yk.psu.edu/~lxn/IST_210/normal_form_definitions.html

5/6

6/2/2015

NormalFormDefinitions&Examples

SUPPLIER_INFO(supplier_no,city,zip)
SUPPLIER_NAME(supplier_no,supplier_name)
LarryNewcomer(UpdatedJanuary06,2000)

http://www2.yk.psu.edu/~lxn/IST_210/normal_form_definitions.html

6/6

Вам также может понравиться