0% found this document useful (0 votes)
25 views40 pages

Lecture 4

The document provides an overview of logical database design and the relational model. It discusses key concepts such as the relational data model, relations, keys, integrity constraints, transforming ER diagrams into relations, and data normalization. The goal is to introduce students to logical database design principles and the relational model.

Uploaded by

David Ezekiel
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
25 views40 pages

Lecture 4

The document provides an overview of logical database design and the relational model. It discusses key concepts such as the relational data model, relations, keys, integrity constraints, transforming ER diagrams into relations, and data normalization. The goal is to introduce students to logical database design principles and the relational model.

Uploaded by

David Ezekiel
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 40

LECTURE FOUR

Logical Database Design and


the Relational Model

WIT 218/ITW 210 Intro. To Database Management Systems


Nora Agyei-Ababio
10244419
Learning Outcomes
• Relational Data Model
• Correspondence with E-R Model
• Relational Keys
• Integrity Constraints
• Transforming E-R Diagrams into Relations
• Data Normalization

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:

Data Structure – data are organized in the form of


tables, with rows and columns.
Data Manipulation – powerful operations are used to
manipulate data stored in the relations.
Data Integrity – the model includes mechanisms to
specify business rules that maintain the integrity of
data when they are manipulated.

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.

Rows correspond with the entity instances.

Columns correspond with attributes.

NB: The word relation in a relational database is NOT


the same as relationship in E-R model.

16-Oct-23 Slide 6
Relational Keys
Primary Key – an attribute or combination of attributes
that uniquely identifies each row in a relation.

Composite Key – a primary key that consists of more than


one attribute.

Foreign Key – an attribute in a relation that serves as a


primary key of another relation in the same database.

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)

adopted by the organization. Combined, these are a composite


primary key (uniquely identifies the
order line)…individually they are
foreign keys (implement M:N
relationship between order and product)

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.

The major types of integrity constraints are domain


constraints, entity integrity and referential integrity.

16-Oct-23 Slide 9
Domain Constraints
Domain Constraints – a domain is the set of values that
may be assigned to an attribute.

All of the values that appear in column of a relation


must be from the same domain.

A domain definition usually consists of domain name,


meaning, data type, size or length and allowable values
for an attribute.

16-Oct-23 Slide 10
Domain Constraints

16-Oct-23 Slide 11
Entity Integrity Rule

The entity integrity rule is designed to ensure that


every relation has a primary key and that the data
values for that primary key are all valid. It guarantees
that every primary key attribute is not null.

16-Oct-23 Slide 12
Referential Integrity Constraint

A rule that states that either each foreign key value


must match a primary key value in another relation or
the foreign key value must be null.

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

(b) CUSTOMER relation

16-Oct-23 Slide 15
Transforming E-R Diagrams into
Relations
(a) CUSTOMER
entity type with
composite
attribute

(b) CUSTOMER relation with address detail

16-Oct-23 Slide 16
Transforming E-R Diagrams into
Relations
(a)

Multivalued attribute becomes a separate relation with foreign key


(b)

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

Composite primary 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.

All relations are in 1st normal form.

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.

A partial functional dependency exists when a non-key


attribute is functionally dependent on part, but not all
of the primary key.

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

04-200 Abigail MD 16 BMS WIT 218 DBMS 001 Nora 406 A

04-200 Abigail MD 16 BMS WIT 208 App II 003 Dorcas 406 B

09-300 John CT 20 BIT ITW 405 Commerce 002 Sam 408 C

09-300 John CT 20 BIT WIT 218 DBMS 001 Nora 406 B

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:

1. In what normal form is the relation?


2. Draw a relational schema and diagram the
functional dependencies in the relation.
3. Convert GRADE REPORT relation into 2NF and 3NF

16-Oct-23 Slide 38
Summary

Two students to summarize the lecture

16-Oct-23 Slide 39
16-Oct-23 Slide 40

You might also like