Normal Forms By Christopher Archibald October 16 th 2007.
-
Upload
lydia-shepherd -
Category
Documents
-
view
217 -
download
1
Transcript of Normal Forms By Christopher Archibald October 16 th 2007.
Normal FormsNormal Forms
By Christopher ArchibaldBy Christopher Archibald
October 16October 16thth 2007 2007
OverviewOverview
Database NormalizationDatabase Normalization
11stst Normal Form Normal Form
22ndnd Normal Form Normal Form
33rdrd Normal Form Normal Form
Boyce- Codd Normal Form (BCNF)Boyce- Codd Normal Form (BCNF)
Lossless-JoinLossless-Join
NormalizationNormalization
Normalization is a technique for designing Normalization is a technique for designing relational table to:relational table to: Minimize duplication of informationMinimize duplication of information Reduce the potential for data anomaliesReduce the potential for data anomalies
Normal FormNormal Form
Normal forms provide a stepwise Normal forms provide a stepwise progression toward the goal of fully progression toward the goal of fully normalized relation schema that are free normalized relation schema that are free for data redundancies.for data redundancies.
First Normal Form (1NF)First Normal Form (1NF)
1NF definition: A schema R is in 1NF only 1NF definition: A schema R is in 1NF only when the attributes comprising the when the attributes comprising the schema are atomic and single-valuedschema are atomic and single-valued No Multi-valued attributesNo Multi-valued attributes No composite attributesNo composite attributes No repeating groups (2 columns can not store No repeating groups (2 columns can not store
similar information)similar information) Can’t have a Null AttributeCan’t have a Null Attribute Must have a Primary KeyMust have a Primary Key
First Normal Form First Normal Form ExampleExample
This is in 1NF (Has primary Key, no repeating This is in 1NF (Has primary Key, no repeating group, No Null attributes and No multivariablegroup, No Null attributes and No multivariable
What happens if James gets a Second Phone What happens if James gets a Second Phone Number?Number?
First Normal FormFirst Normal FormExampleExample
No longer in 1NF because Telephone Number No longer in 1NF because Telephone Number has a multivariable.has a multivariable.
Now we need to redesign our tableNow we need to redesign our table
First Normal FormFirst Normal FormExampleExample
Not in First Normal forumNot in First Normal forum Tel. No. 3 is a null attributeTel. No. 3 is a null attribute Tel. No. 1-2 repeat similar information (Repeating Tel. No. 1-2 repeat similar information (Repeating
group)group)
First Normal FormFirst Normal Form
This is in First Normal This is in First Normal FormForm
Telephone Number is Telephone Number is no long a repeating no long a repeating groupgroup
No MultivariableNo Multivariable
No Null AttributesNo Null Attributes
Has a Primary KeyHas a Primary Key
Second Normal Form (2NF)Second Normal Form (2NF)
2NF Definition: A relation schema R is in 2NF Definition: A relation schema R is in 2NF if every non-prime attribute in R is 2NF if every non-prime attribute in R is fully functionally dependent on the primary fully functionally dependent on the primary key of R.key of R. Must be 1NFMust be 1NF An Attribute that is not part of the candidate An Attribute that is not part of the candidate
key must be dependent on the candidate key key must be dependent on the candidate key and not a part of the candidate keyand not a part of the candidate key
Second Normal FormSecond Normal FormExampleExample
Only Candidate key is Only Candidate key is (Employee, Skill)(Employee, Skill)
Not in 2NFNot in 2NF
Current Work Location is Current Work Location is dependent on Employeedependent on Employee
Can Cause an AnomalyCan Cause an Anomaly
Updating Jones Work location for Typing and Shorthand but not Whittling. Then asking “What is Jones current work location”, can cause a contradictory answer, because there are 2 different locations.
Second Normal Form Second Normal Form ExampleExample
Both tables are in Both tables are in 2NF2NF
Meets 1NF Meets 1NF requirementsrequirements
No non-primary key No non-primary key attribute is dependent attribute is dependent on part of a key.on part of a key.
1NF and 2NF1NF and 2NF1NF and 2NF remove most anomalies1NF and 2NF remove most anomalies
Following table is in 2NFFollowing table is in 2NF
There is redundancy under Winner/Winner DoBThere is redundancy under Winner/Winner DoB Al Fredrickson and Chip MastersonAl Fredrickson and Chip Masterson Can cause an anomalyCan cause an anomaly
Third Normal Form (3NF)Third Normal Form (3NF)
3NF Definition: A relation schema R is in 3NF Definition: A relation schema R is in 3NF if no non-prime attribute is 3NF if no non-prime attribute is functionally dependent on another non-functionally dependent on another non-prime attribute in Rprime attribute in R Table must be in 2NFTable must be in 2NF Eliminate field that do not depended on the Eliminate field that do not depended on the
primary key by placing them in different tablesprimary key by placing them in different tables
Third Normal FormThird Normal FormExampleExample
Table is in 2NF but fails to meet 3NFTable is in 2NF but fails to meet 3NFWinner Date of Birth is Dependent on WinnerWinner Date of Birth is Dependent on Winner If Al Fredrickson Date of birth is update in the first row If Al Fredrickson Date of birth is update in the first row
but not the second ask, “What Al Fredrickson Date of but not the second ask, “What Al Fredrickson Date of birth” will result in 2 different dates.birth” will result in 2 different dates.
Third Normal FormThird Normal FormExampleExample
Table is in 3NFTable is in 3NF Meets 1NF and 2NFMeets 1NF and 2NF No non-primary Key No non-primary Key
attribute is Dependent attribute is Dependent on another non-on another non-primary Key attributeprimary Key attribute
Update Anomalies Update Anomalies cannot occur in these cannot occur in these tablestables
Boyce-Codd Normal Form (BCNF)Boyce-Codd Normal Form (BCNF)
BCNF Definition: A relation Schema R is BCNF Definition: A relation Schema R is in BCNF if for every non-trivial functional in BCNF if for every non-trivial functional dependency in R, the determinant is a dependency in R, the determinant is a superkey of Rsuperkey of R Does not allow Functional Dependency that is Does not allow Functional Dependency that is
not part of a Candidate keynot part of a Candidate key
Most 3NF meet the requirement of a Most 3NF meet the requirement of a BCNFBCNF
Boyce-Codd Normal FormBoyce-Codd Normal FormExampleExample
Candidate key (Tutor ID, Student ID) And (SSN, Candidate key (Tutor ID, Student ID) And (SSN, Student ID)Student ID)
Table is in 3NF, but not BCNFTable is in 3NF, but not BCNF
SNN is dependent on Tutor ID but (Tutor id, SNN) is SNN is dependent on Tutor ID but (Tutor id, SNN) is not a Candidate keynot a Candidate key
Other Normal FormsOther Normal Forms
There is alsoThere is also Fourth normal formFourth normal form Fifth normal FormFifth normal Form Domain/key Normal formDomain/key Normal form Sixth normal formSixth normal form
Which will be covered in chapter 9Which will be covered in chapter 9
Lossless-Join DecompositionLossless-Join Decomposition
The principle behind Lossless-Join The principle behind Lossless-Join decomposition is that the decomposition of decomposition is that the decomposition of a relation schema, R, should be strictly a relation schema, R, should be strictly reversible, i.e.reversible, i.e.
When we break tuples in to different tables When we break tuples in to different tables for normalization we should be able to for normalization we should be able to combined them and get what we startedcombined them and get what we started
Lossless-Join DecompositionLossless-Join Decomposition
Flight #Flight # OriginOrigin DestinationDestination MileageMileage
DL723DL723 BostonBoston St. LouisSt. Louis 12141214
DL577DL577 DenverDenver Los AngelesLos Angeles 11001100
DL5219DL5219 MinneapolisMinneapolis St. LouisSt. Louis 580580
DL357DL357 ChicagoChicago DallasDallas 10581058
DL555DL555 DenverDenver HoustonHouston 11001100
DL5237DL5237 ClevelandCleveland St. LouisSt. Louis 580580
Lossless-Join DecompositionLossless-Join Decomposition
OriginOrigin DestinationDestination MileageMileage
BostonBoston St. LouisSt. Louis 12141214
DenverDenver Los AngelesLos Angeles 11001100
MinneapolisMinneapolis St. LouisSt. Louis 580580
ChicagoChicago DallasDallas 10581058
DenverDenver HoustonHouston 11001100
ClevelandCleveland St. LouisSt. Louis 580580
Flight #Flight # MileageMileage
DL723DL723 12141214
DL577DL577 11001100
DL5219DL5219 580580
DL357DL357 10581058
DL555DL555 11001100
DL5237DL5237 580580
Lossless-Join DecompositionLossless-Join DecompositionFlight #Flight # OriginOrigin DestinationDestination MileageMileage
DL723DL723 BostonBoston St. LouisSt. Louis 12141214
DL577DL577 DenverDenver Los AngelesLos Angeles 11001100
DL577DL577 DenverDenver HoustonHouston 11001100
DL5219DL5219 MinneapolisMinneapolis St. LouisSt. Louis 580580
DL5219DL5219 ClevelandCleveland St. LouisSt. Louis 580580
DL357DL357 ChicagoChicago DallasDallas 10581058
DL555DL555 DenverDenver Lost AngelesLost Angeles 11001100
DL555DL555 DenverDenver HoustonHouston 11001100
DL5237DL5237 MinneapolisMinneapolis St. LouisSt. Louis 580580
DL5237DL5237 ClevelandCleveland St. LouisSt. Louis 580580