Chapter 5
Chapter 5
Logical Database
Design
1
Introduction
Normalization
3
Relation
A relation is a named, two-dimensional table of data
Requirements:
– Every relation has a unique name
– Every attribute value is atomic (not multi-valued, not
composite)
– Every row is unique (can’t have two rows with exactly the
same values for all their fields)
– Attributes (columns) in tables have unique names
– The order of the columns is irrelevant 4
Key Fields
Keys are special fields that serve two main purposes:
7
Mapping a composite attribute
8
Mapping multi-valued attribute
9
ERD to Relational Table(3)
2. Mapping Binary Relationships
One-to-Many
– primary key on the one side becomes a foreign key on the
many side
Many-to-Many
– create a new relation with the primary keys of the two entities
as its primary key
One-to-One
– primary key on the mandatory side becomes a foreign key on
the optional side
– avoids the need to store null values in the foreign key
– any attributes associated with the relationship are also
included in the same relation as the foreign key
10
Mapping a 1:M relationship(1)
(a) Relationship between customers and orders
11
Mapping a 1:M relationship(2)
(b) Mapping the relationship
Foreign key
12
Mapping an M:N relationship(1)
14
Mapping a binary 1:1 relationship(1)
(a) Binary 1:1 relationship
15
Mapping a binary 1:1 relationship(2)
(b) Resulting relations
Note:
• Nurse_in_Charge is another name for Nurse_ID.
• Attribute attached to relationship is stored with foreign key.
16
Anomalies
Types of anomalies
• Insertion anomaly
• adding new rows forces user to create duplicate data
• Deletion anomaly
• deleting rows may cause a loss of data that would be
needed for other future rows
• Modification/updating anomaly
• changing data in a row forces changes to other rows
because of duplication
17
Normalization
The purpose of normalization is to reduce the chances for anomalies
to occur in a database.
Primarily a tool to validate and improve a logical design so that it
satisfies certain constraints that avoid unnecessary duplication of data
Process of decomposing relations with anomalies to produce smaller,
well-structured relations
Database Normalization is the process of removing redundant data
from the tables to improve storage efficiency, data integrity, and
scalability.
18
Functional Dependency (1)
Partial dependency
19
Functional Dependency (2)
Total dependency
Transitive dependency
• If B functionally governs C
First Normal Form: Find the key with which you can find all
data.
Second Normal Form: Remove part-key dependencies.
Make all data dependent on the whole key.
Third Normal Form: Remove non-key dependencies. Make
all data dependent on nothing but the key.
Note: For most practical purposes, databases are considered
22
First Normal Form (1)
• a table (relation) is in 1NF ,If
All repeating groups are moved into a new table/ Distribute the multi-
valued attributes into different rows and identify a unique identifier for
the relation
24
First Normal Form
25
Second Normal Form (1)
EMP_PROJ rearranged
28
Third Normal Form(1)
Remove any transitive dependencies
• This schema is in its 2NF since the primary key is a single attribute.
• Let’s take StudID, Year and Dormitary and see the dependencies.
• StudIDYear AND YearDormitary
• And Year can not determine StudID and Dormitary cannot determine StudID.
Then transitively StudIDDormitary.
• To convert it to a 3NF we need to remove all transitive dependencies of non
key attributes on another non-key attribute.
• The non-primary key attributes, dependent on each other will be moved to
another table and linked with the main table using candidate key- foreign
30 key
Cont.…
31
Other Forms of Normalization
Boyce-Codd Normal Form (BCNF)
• A table is in BCNF if it is in 3NF and if every determinant is a
candidate key.
Fourth Normal form (4NF)
• A table is in 4NF if it is in BCNF and if it has no multi-valued
dependencies
Fifth Normal Form (5NF)
• Projection-Join Normal Form" (PJNF),
• if it is in 4NF and if every join dependency in the table is a
consequence of the candidate keys of the table.
Domain-Key Normal Form (DKNF)
• A table is in DKNF if every constraint on the table is a logical
consequence of the definition of keys and domains.
• A model free from all modification anomalies.
32
Outcomes of Normalization
Contain all the data necessary for the purposes that the
database is to serve.
33
Pitfalls of Normalization
Requires data to see the problems
Is time consuming
34