Relational Database Design (Normalization
Relational Database Design
Why is Database Normalization Important?�
Normalization helps a database designer optimally distribute attributes into tables. The technique eliminates the following:
Although total database normalization is not necessary, it provides a well-functioning information environment.
The method systematically ensures:
Database normalization transforms overall database consistency, providing an efficient environment.
The Banking Schema
Combine Schemas?
A Combined Schema Without Repetition
loan_amt_br = (loan_number, amount, branch_name)
What About Smaller Schemas?
A Lossy Decomposition
Definition Normalization
Levels of Normalization
Redundancy
Number of Tables
Most databases should be 3NF or BCNF in order to avoid the database anomalies.
Complexity
Levels of Normalization
Each higher level is a subset of the lower level
1NF
5NF
4NF
3NF
2NF
DKNF
First Normal Form
First Normal Form (Cont’d)
A table is considered to be in 1NF if all the fields contain
only scalar values (as opposed to list of values).
Example (Not 1NF)
First Normal Form (1NF) Example
Author and AuPhone columns are not scalar
Example (1NF)
1NF - Decomposition-Example
0-321-32132-1
Balloon
Small House
714-000-0000
$34.00
0-55-123456-9
Main Street
Small House
714-000-0000
$22.95
0-123-45678-0
Ulysses
Alpha Press
999-999-9999
$34.00
1-22-233700-0
Visual Basic
Big House
123-456-7890
$25.00
ISBN
Title
PubName
PubPhone
Price
ISBN
AuName
AuPhone
0-123-45678-0
Joyce
666-666-6666
1-22-233700-0
Roman
444-444-4444
0-55-123456-9
Smith
654-223-3455
0-55-123456-9
Jones
123-333-3333
0-321-32132-1
Grumpy
665-235-6532
0-321-32132-1
Snoopy
232-234-1234
0-321-32132-1
Sleepy
321-321-1111
Goal — Devise a Theory for the Following
1.1 Semantics of the Relation Attributes
GUIDELINE 1: Informally, each tuple in a relation should represent one entity or relationship instance. (Applies to individual relations and their attributes).
Bottom Line: Design a schema that can be explained easily relation by relation. The semantics of attributes should be easy to interpret.
17
1.2 Redundant Information in Tuples and Update Anomalies
20
EXAMPLE OF AN UPDATE ANOMALY (1)
Consider the relation:
EMP_PROJ ( Emp#, Proj#, Ename, Pname, No_hours)
21
Figure: Two relation schemas suffering from update anomalies
Figure: Example States for EMP_DEPT and EMP_PROJ
Guideline to Redundant Information in Tuples and Update Anomalies
1.3 Null Values in Tuples
GUIDELINE 3: Relations should be designed such that their tuples will have as few NULL values as possible
1.4 Spurious Tuples
GUIDELINE 4: The relations should be designed to satisfy the lossless join condition. No spurious tuples should be generated by doing a natural-join of any relations.
There are two important properties of decompositions:
Note that property (a) is extremely important and cannot be sacrificed. Property (b) is less stringent and may be sacrificed.
Functional Dependencies
t1[α] = t2 [α] ⇒ t1[β ] = t2 [β ]
1 5
3 7
Example 1
Functional Dependencies
0-321-32132-1
Balloon
$34.00
0-55-123456-9
Main Street
$22.95
0-123-45678-0
Ulysses
$34.00
1-22-233700-0
Visual Basic
$25.00
ISBN
Title
Price
Table Scheme: {ISBN, Title, Price}
Functional Dependencies: {ISBN} 🡪 {Title}
{ISBN} 🡪 {Price}
Example 2
Functional Dependencies
1
Big House
999-999-9999
2
Small House
123-456-7890
3
Alpha Press
111-111-1111
PubID
PubName
PubPhone
Table Scheme:{PubID,PubName,PubPhone}
Functional Dependencies:
{PubId} 🡪 {PubPhone}
{PubId} 🡪 {PubName}
{PubName, PubPhone} 🡪 {PubID}
AuID
AuName
AuPhone
6
Joyce
666-666-6666
7
Roman
444-444-4444
5
Smith
654-223-3455
4
Jones
123-333-3333
3
Grumpy
665-235-6532
2
Snoopy
232-234-1234
1
Sleepy
321-321-1111
Example 3
Table Scheme:
{AuID, AuName, AuPhone}
Functional Dependencies:
{AuId} 🡪 {AuPhone}
{AuId} 🡪 {AuName}
{AuName, AuPhone} 🡪 {AuID}
Database to track reviews of papers submitted to an academic conference. Prospective authors submit papers for review and possible acceptance in the published conference proceedings. Details of the entities
FD – Example
Functional Dependencies
FD – Example
Inference Rules For FDs
Inference Rules For FDs
For a table to be in 2NF,
(No non prime attribute is dependent on the proper subset of any candidate key of the table)
Note: Remember that we are dealing with non-key attributes
Example 1 (Not 2NF)
Scheme 🡪 {Title, PubId, AuId, Price, AuAddress}
Second Normal Form (2NF)
Example 1 (Convert to 2NF)
Old Scheme 🡪 {Title, PubId, AuId, Price, AuAddress}
New Scheme 🡪 {Title, PubId, AuId, Price}
New Scheme 🡪 {AuId, AuAddress}
2NF - Decomposition
Example 2 (Not 2NF)
Scheme 🡪 {City, Street, HouseNumber, HouseColor, CityPopulation}
Example 3 (Not 2NF)
Scheme 🡪 {studio, movie, budget, studio_city}
Second Normal Form (2NF)
Example 2 (Convert to 2NF)
Old Scheme 🡪 {Studio, Movie, Budget, StudioCity}
New Scheme 🡪 {Movie, Studio, Budget}
New Scheme 🡪 {Studio, City}
Example 3 (Convert to 2NF)
Old Scheme 🡪 {City, Street, HouseNumber, HouseColor, CityPopulation}
New Scheme 🡪 {City, Street, HouseNumber, HouseColor}
New Scheme 🡪 {City, CityPopulation}
2NF - Decomposition
This form dictates that all non-key attributes of a table must be functionally dependent on a candidate key i.e. there can be no interdependencies among non-key attributes.
For a table to be in 3NF, there are two requirements
Example (Not in 3NF)
Scheme 🡪 {Title, PubID, PageCount, Price }
Third Normal Form (3NF)
Example 1 (Convert to 3NF)
Old Scheme 🡪 {Title, PubID, PageCount, Price }
New Scheme 🡪 {PubID, PageCount, Price}
New Scheme 🡪 {Title, PubID, PageCount}
3NF - Decomposition
Example 2 (Not in 3NF)
Scheme 🡪 {Studio, StudioCity, CityTemp}
Example 3 (Not in 3NF)
Scheme 🡪 {BuildingID, Contractor, Fee}
Third Normal Form (3NF)
BuildingID
Contractor
Fee
100
Randolph
1200
150
Ingersoll
1100
200
Randolph
1200
250
Pitkin
1100
300
Randolph
1200
Example 2 (Convert to 3NF)
Old Scheme 🡪 {Studio, StudioCity, CityTemp}
New Scheme 🡪 {Studio, StudioCity}
New Scheme 🡪 {StudioCity, CityTemp}
Example 3 (Convert to 3NF)
Old Scheme 🡪 {BuildingID, Contractor, Fee}
New Scheme 🡪 {BuildingID, Contractor}
New Scheme 🡪 {Contractor, Fee}
3NF - Decomposition
BuildingID
Contractor
100
Randolph
150
Ingersoll
200
Randolph
250
Pitkin
300
Randolph
Contractor
Fee
Randolph
1200
Ingersoll
1100
Pitkin
1100
Third Normal Form Definition
α → β in F+�at least one of the following holds:
(NOTE: each attribute may be in a different candidate key)
Boyce-Codd Normal Form (BCNF)
Example 1 - Address (Not in BCNF)
Scheme 🡪 {City, Street, ZipCode }
Boyce-Codd Normal Form (BCNF)
Example 1 (Convert to BCNF)
Old Scheme 🡪 {City, Street, ZipCode }
New Scheme1 🡪 {ZipCode, Street}
New Scheme2 🡪 {City, Street}
Alternate New Scheme1 🡪 {ZipCode, Street }
Alternate New Scheme2 🡪 {ZipCode, City}
Decomposition – Loss of Information
Use your own judgment when decomposing schemas
Example 2 - Movie (Not in BCNF)
Scheme 🡪 {MovieTitle, MovieID, PersonName, Role, Payment }
Example 3 - Consulting (Not in BCNF)
Scheme 🡪 {Client, Problem, Consultant}
Boyce Codd Normal Form (BCNF)
Example 2 (Convert to BCNF)
Old Scheme 🡪 {MovieTitle, MovieID, PersonName, Role, Payment }
New Scheme 🡪 {MovieID, PersonName, Role, Payment}
New Scheme 🡪 {MovieTitle, PersonName}
New Scheme 🡪 {MovieID, PersonName, Role, Payment}
New Scheme 🡪 {MovieID, MovieTitle}
Example 3 (Convert to BCNF)
Old Scheme 🡪 {Client, Problem, Consultant}
New Scheme 🡪 {Client, Consultant}
New Scheme 🡪 {Client, Problem}
BCNF - Decomposition
Comparison of BCNF and 3NF
Example of BCNF Decomposition
Example of BCNF Decomposition
R = (branch_name, branch_city, assets,
customer_name, loan_number, amount )
F = {branch_name → assets branch_city
loan_number → amount branch_name }
Key = {loan_number, customer_name}
Fourth Normal Form (4NF)
MVD (Cont.)
α →→ β
holds on R if in any legal relation r(R), for all pairs for tuples t1 and t2 in r such that t1[α] = t2 [α], there exist tuples t3 and t4 in r such that:
t1[α] = t2 [α] = t3 [α] = t4 [α] � t3[β] = t1 [β] � t3[R – β] = t2[R – β] � t4 [β] = t2[β] � t4[R – β] = t1[R – β] �
Example (Not in 4NF)
Scheme 🡪 {MovieName, ScreeningCity, Genre)
Primary Key: {MovieName, ScreeningCity, Genre)
Fourth Normal Form (4NF)
Movie
ScreeningCity
Genre
Hard Code
Los Angles
Comedy
Hard Code
New York
Comedy
Bill Durham
Santa Cruz
Drama
Bill Durham
Durham
Drama
The Code Warrier
New York
Horror
Example 2 (Not in 4NF)
Scheme 🡪 {Manager, Child, Employee}
Example 3 (Not in 4NF)
Scheme 🡪 {Employee, Skill, ForeignLanguage}
Fourth Normal Form (4NF)
Manager
Child
Employee
Jim
Beth
Alice
Mary
Bob
Jane
Mary
NULL
Adam
Employee
Skill
Language
1234
Cooking
French
1234
Cooking
German
1453
Carpentry
Spanish
1453
Cooking
Spanish
2345
Cooking
Spanish
Example 1 (Convert to 3NF)
Old Scheme 🡪 {MovieName, ScreeningCity, Genre}
New Scheme 🡪 {MovieName, ScreeningCity}
New Scheme 🡪 {MovieName, Genre}
4NF - Decomposition
Movie
Genre
Hard Code
Comedy
Bill Durham
Drama
The Code Warrier
Horror
Movie
ScreeningCity
Hard Code
Los Angles
Hard Code
New York
Bill Durham
Santa Cruz
Bill Durham
Durham
The Code Warrier
New York
Example 2 (Convert to 4NF)
Old Scheme 🡪 {Manager, Child, Employee}
New Scheme 🡪 {Manager, Child}
New Scheme 🡪 {Manager, Employee}
Example 3 (Convert to 4NF)
Old Scheme 🡪 {Employee, Skill, ForeignLanguage}
New Scheme 🡪 {Employee, Skill}
New Scheme 🡪 {Employee, ForeignLanguage}
4NF - Decomposition
Manager
Child
Jim
Beth
Mary
Bob
Manager
Employee
Jim
Alice
Mary
Jane
Mary
Adam
Employee
Language
1234
French
1234
German
1453
Spanish
2345
Spanish
Employee
Skill
1234
Cooking
1453
Carpentry
1453
Cooking
2345
Cooking
Fifth Normal Form (5NF)
Domain Key Normal Form (DKNF)
Conversion to First Normal Form (continued)
Conversion to Second Normal Form (continued)
Conversion to Third Normal Form (continued)
The Boyce-Codd Normal Form (BCNF) (continued)
Example Multivalued FD and Normalization to 4Th Normal Form
F ={ A →→ B
B →→ HI
CG →→ H }
a) R1 = (A, B) (R1 is in 4NF)
b) R2 = (A, C, G, H, I) (R2 is not in 4NF)
c) R3 = (C, G, H) (R3 is in 4NF)
d) R4 = (A, C, G, I) (R4 is not in 4NF)
e) R5 = (A, I) (R5 is in 4NF)
f)R6 = (A, C, G) (R6 is in 4NF)