Lecture 4
Lecture 4
16-Oct-23 Slide 2
The Relational Data Model
The relational data model represents data in the form
of tables. It consists of three components:
16-Oct-23 Slide 3
Relational Data Model
A relation is a named, two-dimensional table of data.
The table consists of rows (records) and columns (attribute
or field).
Requirements for a table to qualify as a relation
▪ It must have a unique name
▪ Every attribute value must be atomic (not multi-valued,
not composite)
▪ Every row must be unique
▪ Attributes in tables must have unique names
▪ The order of the columns can be irrelevant
▪ The order of the rows can be irrelevant
16-Oct-23 Slide 4
STUDENT RELATION
STUDENT ID NAME PROGRAMME LEVEL
WIUC/04/2169 ABRAFI OFORI BMS 200L
WIUC/04/2000 PATRICIA BMS 200L
WIUC/09/2002 CALEB BIT 200L
16-Oct-23 Slide 5
Correspondence with E-R Model
Relations (tables) correspond with the entity.
16-Oct-23 Slide 6
Relational Keys
Primary Key – an attribute or combination of attributes
that uniquely identifies each row in a relation.
16-Oct-23 Slide 7
Relational Keys
▪ Be repeatable – meaning that different people or the
same person at different times should develop the
same name. Primary Key
▪ Follow a standard syntax – meaning that the Foreign
partsKey of
(implements 1:N relationship
the name should follow a standardbetween arrangement
customer and order)
16-Oct-23 Slide 8
Integrity Constraints
The relational data model includes several types of
constraints or rules limiting acceptable values and
actions to maintain the accuracy and integrity of data in
the database.
16-Oct-23 Slide 9
Domain Constraints
Domain Constraints – a domain is the set of values that
may be assigned to an attribute.
16-Oct-23 Slide 10
Domain Constraints
16-Oct-23 Slide 11
Entity Integrity Rule
16-Oct-23 Slide 12
Referential Integrity Constraint
16-Oct-23 Slide 13
Referential Integrity Constraint
Referential
integrity
constraints are
drawn via arrows
from dependent to
parent table
16-Oct-23 Slide 14
Transforming E-R Diagrams into
Relations
(a) CUSTOMER
entity type with
simple
attributes
16-Oct-23 Slide 15
Transforming E-R Diagrams into
Relations
(a) CUSTOMER
entity type with
composite
attribute
16-Oct-23 Slide 16
Transforming E-R Diagrams into
Relations
(a)
16-Oct-23 Slide 17
Transforming E-R Diagrams into
Relations
16-Oct-23 Slide 18
Transforming E-R Diagrams into
Relations
NOTE: the domain constraint
for the foreign key should
NOT allow null value if
DEPENDENT is a weak
entity
Foreign key
16-Oct-23 Slide 19
Transforming E-R Diagrams into
Relations
16-Oct-23 Slide 20
Transforming E-R Diagrams into
Relations
Mapping the relationship
16-Oct-23 Slide 21
Data Normalization
Normalization is the process of decomposing relations with
anomalies to produce smaller, well-structured relations. It serves
as a tool to validate and improve a logical design so that it
satisfies certain constraints that avoid unnecessary duplication of
data.
Main goals of normalization
▪ Minimize data redundancy, thereby avoiding anomalies and
conserving storage space.
▪ Simplify the enforcement of referential integrity constraints.
▪ Make it easier to maintain data
▪ Provide a better and improved design of organizational data.
16-Oct-23 Slide 22
Well-Structured Relations
• A relation that contains minimal data redundancy and
allows users to insert, delete, and update rows without
causing data inconsistencies.
• Goal is to avoid 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 Anomaly–changing data in a row forces
changes to other rows because of duplication
16-Oct-23 Slide 23
Steps In Normalization
A normal form is a state of relation that requires that
certain rules regarding relationships between attributes
are satisfied. The steps in normalization include:
▪ First normal form
▪ Second normal form
▪ Third normal form
▪ Boyce-Codd normal form
▪ Fourth normal form
▪ Fifth normal form
16-Oct-23 Slide 24
Steps In Normalization
16-Oct-23 Slide 25
First Normal Form (1NF)
Any multivalued attributes should be removed, so that
there is a single value at the intersection of each row
and column of the table.
16-Oct-23 Slide 26
First Normal Form
Table with multivalued attributes, not in 1st normal form
16-Oct-23 Slide 27
First Normal Form
Table with no multivalued attributes and unique rows, in 1st
normal form
16-Oct-23 Slide 28
First Normal Form
Anomalies in this table
• Insertion–if new product is ordered for order 1007 of
existing customer, customer data must be re-
entered, causing duplication
• Deletion–if we delete the Dining Table from Order
1006, we lose information concerning this item's
finish and price
• Update–changing the price of product ID 4 requires
update in several records
16-Oct-23 Slide 29
Second Normal Form
Functional Dependency – a constraint between two
attributes in which the value of one attribute is
determined by the value of another attribute.
16-Oct-23 Slide 30
Second Normal Form
A relation is in second normal form (2NF) if it is in the 1NF
and contains no partial functional dependencies.
Every non-key attribute is fully functionally dependent on
the entire primary key.
To convert a relation with partial dependencies to 2NF,
➢ Create a new relation for each primary key attribute that
is a determinant in a partial dependency. That attribute is
the primary key in the new relation.
➢ Move the non-key attributes that are dependent on this
primary key attribute from the old relation to the new
relation.
16-Oct-23 Slide 31
Second Normal Form
16-Oct-23 Slide 32
Second Normal Form
16-Oct-23 Slide 33
Third Normal Form
A relation is in third normal form (3NF) if it is in 2NF
and no transitive dependencies exist.
A transitive dependency in a relation is a functional
dependency between the primary key and one or more
non-key attributes that are dependent on the primary
key through another non-key attribute.
Transitive dependencies create unnecessary
redundancy that may lead to anomalies.
16-Oct-23 Slide 34
Third Normal Form
Removing transitive dependencies:
➢ For each non-key attribute that is a determinant in a
relation, create a new relation. That attribute becomes
the primary key of the new relation.
➢ Move all the attributes that are functionally dependent
on the primary key of the new relation from the old to
the new relation.
➢ Leave the attribute that serves as a primary key in the
new relation in the old relation to serve as a foreign key
that allows you to associate the two relations.
16-Oct-23 Slide 35
Third Normal Form
16-Oct-23 Slide 36
Activity
StudID StudName StudAdd Prog CourseID Title LectID LectName Office Grade
06-400 Kofi KN 40 DIT DIT 202 Info Tech 004 Isaac 405 A
16-Oct-23 Slide 37
Activity
The figure above shows a GRADE REPORT relation for a
university. With reference to it, answer the following:
16-Oct-23 Slide 38
Summary
16-Oct-23 Slide 39
16-Oct-23 Slide 40