Logical Database Design and The Relational Model
Logical Database Design and The Relational Model
Relational Model
Module 4
Objectives
Definition of terms
List properties of a relation
Transform ER/EER diagrams to relations
Define first, second, and third normal form
Describe problems from merging relations
Create tables with entity and relational
integrity constraints
Use normalization to convert anomalous
tables to well-structured relations.
The Physical Design Stage of SDLC
Project Identification
and Selection
Purpose – information requirements structure
Deliverable – detailed design specifications
Project Initiation
and Planning
Analysis
Logical
Logical Design
Design
Physical Design
Database activity –
Implementation
logical database design
Maintenance
Logical Database Design
Process of transforming the conceptual data
model into a logical data model.
EMPLOYEE 1
Emp_ID Name Dept_Name Salary
100 Andy Garcia Marketing 48,000
140 Allen Beeton Accounting 52,000
110 Chris Lucero Info System 42,000
190 Lorenzo Davis Finance 55,000
150 Susan Martin Marketing 42,000
Records
Attributes
6 Properties of a Relation
Has a unique name.
Every attribute value must be atomic (not
multivalued, not composite)
Every row must be unique (no two rows in a
relation are identical).
Attributes (columns) in tables must have
unique names
Order of the columns must be irrelevant
Order of the rows must be irrelevant
NOTE: all relations are in 1st Normal form
Sample Table with Repeating groups
EMPLOYEE 1
Primary Key
Foreign Key
(implements 1:N relationship
between customer and order)
Referential
integrity
constraints are
drawn via arrows
from dependent to
parent table
Referential
integrity
constraints are
implemented
with foreign key
to primary key
references
Well structured Relations
Relation containing minimal redundancy and
allows users to insert, modify, and delete the
rows in a table without error or
inconsistencies.
Anomaly – an error or inconsistency that may
result when a user attempts to update a table
that contains redundant data.
Types of Anomalies
Insertion Anomaly
Deletion Anomaly
Modification Anomaly
Sample table showing types of
Anomalies
(Not a well structured relation)
Emp_ID Name Dept._Name Salary Course_title Date_Completed
Attr2 Attr3
PK Attr1
Composite
Relation1
Relation1 (PK, Attr1, Attr2, Attr3)
PK Attr1
Attr2
Relation1 (PK, Attr1)
Relation1 Relation2(PK, Attr2)
Transforming EER Diagrams into
Relations (cont.)
entity)
Mapping a weak entity
Relations resulting from weak entity
Foreign key
Foreign key
Example of mapping an M:N relationship
New
Foreign key intersection
relation
Foreign key
Mapping a binary 1:1 relationship
In_charge relationship
Resulting relations (1:1)
Nearly always optional on another side
Summary on Binary Relations
1:M
Relation1 (PK1, Attr1)
Relation2 (PK2, PK1, Attr2)
Summary on Binary Relations
M:N
Relation1 (PK1, Attr1)
Relation2 (PK2, Attr2)
Relates (PK1, PK2, Attr3)
Summary on Binary Relations
1:1
Relation1 (PK1, Attr1)
Relation2 (PK2, PK1, Attr2)
Transforming EER Diagrams into
Relations (cont.)
D. Mapping Associative Entities
Identifier Not Assigned
Default primary key for the association relation
is composed of the primary keys of the two
entities (as in M:N relationship)
Identifier Assigned
Itis natural and familiar to end-users
Default identifier may not be unique
Mapping an associative entity with an identifier
Associative entity
Three resulting relations
Summary on Associative Entities
Attr3 PK2
PK1 Attr1 Attr2
PK3 PK2
PK1 Attr1 Attr2
(b) EMPLOYEE
relation with
recursive foreign
key. Need not
have the same
name
Mapping a unary M:N relationship
(a) Bill-of-materials
relationships (M:N)
PK1 Attr1
Relation1
Relates
1:M
PK1 Attr1
Relation1
Relates
Attr2
M:N
These are
implemented as one-
to-one relationships
Illustrative Example #1
Convert ER into a relation
Code Room
Instcode Day
ContactNo Name
registe
r
Address
MemName
MEMBER MemId
Illustrative Example #2
BedNo BED Room
PNo
IN-PATIENT PAddress
PName
A_Date
Procedure attend Bills Charge
PHYSICIAN ITEM
Acct_ID MERCHANT
Given
Card_type
Exp_Date
Date
CARD
ACCOUNT
charge Amount
Bank_no d s
Cur_Bal
Course_Title, Date_Completed)
Other examples:
SSN Name, Address, Bday
Person’s Name, Address, and Bday are functionally
dependent on the person’s SSN
VIN Make, Model, Color
Make, model, and color of a Vehicle are functionally
dependent on the Vehicle identification number.
Determinant
The attribute on the left side of the arrow in
a functional dependency.
AB
Determinant
Candidate Key
A unique identifier. One of the candidate
keys will become the primary key
E.g. Emp_ID, and Couse_Title … in this case
both are candidate keys
TABLE ( A, B, C, D, E, F, G )
Candidate keys
Steps in
normalization
Normal form
A state of a relation that results from
applying simple rules regarding functional
dependencies to that relation.
Zero form
1NF
2NF
4NF
5NF
Step 0: Zero form
Represent the user’s view of a report in
tabular form.
UC Customer INVOICE
Full dependency
Transitive dependencies
Partial Dependency
A dependency in which the value of a non-
key attribute can be uniquely identified using
only part of a concatenated primary key
A B C D E F G H I J K
Step 3: Third Normal Form
2NF PLUS no transitive dependencies
(functional dependencies on non-primary-key
attributes)
Note: this is called transitive, because the
primary key is a determinant for another
attribute, which in turn is a determinant for a
third
Solution: non-key determinant with transitive
dependencies go into a new table; non-key
determinant becomes primary key in the new
table and stays as foreign key in the old table
Sample Third Normal Form
Transitive dependencies are removed
Exercise:
Given the form below, determine and write
the 1st, 2nd and 3rd NFs relations.
XYZ UNIVERSITY
REPORT ON GRADES
2ND TRIMESTER, SY 2005-2006
ID Number: 9729344
Name: Emily Williams
Course: BSIT
Course Instructor
Description Instructor Units Grade
Code Code
CSC 222 Database Management Einstein Eins 3 85
CSC 223 Programming Languages Mozart Moz 3 82
ID NUMBER NAME COURSE COURSE CODE DESCRIPTION INSTRUCTOR INSTRUCTOR CODE UNITS GRADE
Emily
9729344 BSIT 9729344 CSC 222 85
Williams
Steve
9722565 BSIM 9729344 CSC 223 82
Roberts
9729344 Math 4 84
9722565 Phys 1 79
Course_Instructor
Course Instructor
Description Instructor Units
code Code
Database
CSC 222 Einstein Eins 3
Management
Programming
CSC 223 Mozart Moz 3
Languages
Math 4 Statistics Bohr Bohr 3
Phys 1 College Physics 1 White Wht 3
Database
CSC 222 Binstein Bins 3
Management
Third Normal Form
A C B D E
new new
Pk Nk
A C D E C B
Sample BCNF Problem
Each CLASS_CODE identifies a class uniquely.
A student can take many classes, therefore
can earn many grades.
A staff member can teach many classes, but
each class is taught by only one staff
member.