Lecture 4 Examples
Lecture 4 Examples
Database
Lecture 4 Examples
Topics: Bridge
(Composite) Table, CPK, Recursive Relationship, ERD,
Relational Schema, DB Design Goals, DB Design
Development Process
employee
employee_id employee_last_na employee_first_na employee_degree
me me
100 Zeid Abe BS, MS, PhD
employee
employee_id employee_last_na employee_first_na employee_degree
me me
100 Zeid Abe BS, MS, PhD
Solution: 1) Add multiple degree fields – degree 1, degree 2, etc. NOT GOOD
2) Remove degree field column and expand design
Example 1: Bridge (Composite) Table
New Design:
employee degree
employe employee_a employee_fir degree_id degree_name
e_id st_lname st_name
100 Zeid Abe
BS Bachelor
MS Master
PhD Doctoral
AS Associate
employee _ degree
Bridge table allows for
Bridge Table → employ degree degree_dat
ee_id _id e
additional data to be
always has CPK included
100 BS
consisting of 2 or Example – degree date
100 MS
more attributes attribute
100 PhD
Example 2: Bridge (Composite) Table
professor
professo professor_las professor_fir professor_co
r_id t_name st_name urses
person
person_id person_last_name person_first_name person_spouse
Class discussion
Example 4 : M:N Recursive Relationship
employee
employee_id employee_ln employee_f employee_ma M
ame name nage employee
100 N
110
120 100, 130
130
course
course_number course_name course_prerequisite M
course
MATH100 Math 1 N
MATH200 Math 2 MATH100
MATH300 Math 3 MATH200
MATH400 Math 4 MATH300, PHYS400
Class discussion
Example 5: 1:M Recursive Relationship M manage
s
employee
employee manager 1
employe employ employee_f employee_l manager employ manager_d manager_expert
e_id ee_id name name _id ee_id ate ise
100 1 1 120
110 2
3
120
130 1
M requires
prerequisite
course course
1
course_number course_name course_number prerequisite_course
MTH100
MTH200 MTH100
MTH200
MTH300 MTH200
MTH300
MTH400 MTH300
MTH400
MTH400 PHYS450
Entity Relationship Diagram (ERD)
We use ERD and relational schema as DB design and documentation tools
An ERD uses symbols and documents the entity (table) relationships and
their types
An entity relationship diagram (ERD) shows the relationships of entity
sets stored in a database.
An entity in this context is an object, a component of data. An entity set
is a collection of similar entities. These entities can have attributes that
define its properties.
ERD Symbols
• Visio, Lucid Entity (table) lower case
Chart, and
Draw.io are good
tools to draw
ERD symbols
Bridge (composite) table
• Powerpoint can lower case
also be used to Indicates M:N relationship
draw ERD
• Microsoft Word Relationship (activity)
is NOT a good Lowercase verb
tool for
drawing.
Optional Relationship
Relationship (activity)
Lowercase verb
Cardinality is the # of
Optional Relationship occurrences of an entity
in the related entity
written as (x,y) where x is
the lower limit (min) and
y is the upper limit (max)
Class discussion
Example 7: ERD
connectivity
1 M
customer generate invoice
(1, N) (1, 1)
has cardinality
1 M employee_ M 1
employee (1,N)
has
(1,1) degree (1,1)
belongs
to (1,N)
degree
1 M
manager manage employee
(1, N) (1, 1)
1 (1, 1) (1, 1) 1
is
Relational Schema
ERD has a problem; it shows only tables and their relationships, but no attributes or
keys
Relational schema solved this problem; it shows the attributes of each table and their
PKs, CPKs, and/or FKs
Relational schema complements ERD by showing more details
sketch relational schema manually or create it in Access
customer_id 1 invoice_num
ber
customer_firs M
customer_id
t_name
customer_las invoice_date
t_name
THINK: 1) What does the underline indicate?
2) How would you sketch relational schema for a
recursive relationship?
DB Design Goals
DB design goals are
Information
Transaction speed
Redundancy
Maintainability
Expandability
These goals conflict with each other; do your best as a DB designer
DB Design/Development Process
3 Steps
1. Study description and operations
2. Generate business rules; identify system, objects (tables) and attributes
in this step
3. Sketch ERD and relations schema