CSE 344: Section 4
ER diagrams
Jan 29th, 2026
Announcements
Database Design
E/R diagram Basics
Entity set
Attribute
Relationship
Subclass
is a
Weak Entity
Entity Set
Subclass
CREATE TABLE Product (
pname VARCHAR(30) PRIMARY KEY,
price INT)
CREATE TABLE Toy (
pname VARCHAR(30) PRIMARY KEY REFERENCES Product,
age INT)
CREATE TABLE Candy (
pname VARCHAR(30) PRIMARY KEY REFERENCES Product,
isChoc VARCHAR(5))
Relationships
Integrity Constraints in ER Diagrams
Single Value Constraints (many-one) [at most one]
makes
Referential Integrity Constraints (many-one) [exactly one]
makes
Other Constraints
>2
makes
Examples of Relationships
Question: "at most one" vs. "exactly one"?
Keys and FKs
Product
price
name
category
owns
Company
name
E/R to SQL
CREATE TABLE 3PlayerGame (
gid VARCHAR(30) PRIMARY KEY,
player1 VARCHAR(30) NOT NULL REFERENCES Players,
player2 VARCHAR(30) NOT NULL REFERENCES Players,
player3 VARCHAR(30) NOT NULL REFERENCES Players,
)
CREATE TABLE Players (
pid VARCHAR(30) PRIMARY KEY,
name VARCHAR(30)
)
Weak Entity Set
Entity Relationships Example
Entity Relationships Example: Question
Every student can check out at most 5 books. Some books may not be checked out by anyone. Draw the ER diagram. What is the multiplicity?
Entity Relationships Example: Step 1
Every student can check out at most 5 books. Some books may not be checked out by anyone. Draw the ER diagram. What is the multiplicity?
Step 1: Describe the relationship between the entities in english
Entity Relationships Example: Step 1.1
Every student can check out at most 5 books. Some books may not be checked out by anyone. Draw the ER diagram. What is the multiplicity?
Step 1: Describe the relationship between the entities in english
Entity Relationships Example: Step 2
Every student can check out at most 5 books. Some books may not be checked out by anyone. Draw the ER diagram. What is the multiplicity?
Step 1: Describe the relationship between the entities in english
Step 2: Draw entities and relationship
Entity Relationships Example: Step 2.1
Every student can check out at most 5 books. Some books may not be checked out by anyone. Draw the ER diagram. What is the multiplicity?
Step 1: Describe the relationship between the entities in english
Step 2: Draw entities and relationship
Checks out
Student
Book
Entity Relationships Example: Step 3
Every student can check out multiple books
Each book can be checked out by at most one student
Step 3: For each entity, add arrow pointing to it if it is constrained to 1
Entity Relationships Example: Step 3.1
Every student can check out multiple books
Each book can be checked out by at most one student
Step 3: For each entity, add arrow pointing to it if it is constrained to 1
Student
Checks out
Book
Entity Relationships Example: Step 3.2
Every student can check out multiple books
Each book can be checked out by at most one student
Step 3: For each entity, add arrow pointing to it if it is constrained to 1
Student
Checks out
Book
Student
Checks out
<= 5
Book
Entity Relationships Example: Final Solution
Every student can check out at most 5 books. Some books may not be checked out by anyone. Draw the ER diagram. What is the multiplicity?
Final Solution:
Many-to-One
Student
Checks out
<= 5
Book
Follow this same step-by-step formula!
Worksheet Exercise 1:
Entity Relationships & Multiplicity
Worksheet Exercise 1a: Multiplicity Overview
SCENARIO: Every author writes at least one book.
Draw the E/R Diagram and state the multiplicity.
Relevant domain information:
Worksheet Exercise 1a: Multiplicity Solution
SCENARIO: Every author writes at least one book.
Draw the E/R Diagram and state the multiplicity.
Relevant domain information:
Many-to-Many
Author
> 0
writes
> 0
Book
Neither entity is constrained to one, so no arrows
Worksheet Exercise 1b: Multiplicity Overview
SCENARIO: What is the relationship between US State and capital?
Draw the E/R Diagram and state the multiplicity.
Worksheet Exercise 1b: Multiplicity Solution
SCENARIO: What is the relationship between US State and capital?
Draw the E/R Diagram and state the multiplicity.
Each state has exactly one capital.
Each capital belongs to exactly one state.
Both entities constrained to one, so arrows pointing to both
One-to-One
US State
Capital
has
Worksheet Exercise 1c: Multiplicity Overview
SCENARIO: Every city has at most 5 parks. Assume parks are confined to one city (ie. they don’t span across multiple cities).
Draw the E/R Diagram and state the multiplicity.
Worksheet Exercise 1c: Multiplicity Solution
SCENARIO: Every city has at most 5 parks. Assume parks are confined to one city (ie. they don’t span across multiple cities).
Draw the E/R Diagram and state the multiplicity.
Each city can have multiple parks.
Each park is in exactly one city.
City is constrained to one, so arrow points to it.
Many-to-One
City
Park
has
<= 5
Worksheet Exercise 2a:
Entity Relationship Diagrams
Worksheet Exercise 2a: Entity Relationship Diagrams Overview
Odegaard Library is in need of a new database, and they have asked you to help design it! Here are some of the requirements for what information needs to be stored in this database:
Worksheet Exercise 2a: Entity Relationship Diagrams Step 1
book
num_of_pages
id
title
author
Worksheet Exercise 2a: Entity Relationship Diagrams Step 2
book
num_of_pages
id
title
author
Worksheet Exercise 2a: Entity Relationship Diagrams Step 3
book
num_of_pages
id
title
author
has_genre
genre
name
recommended_age
Worksheet Exercise 2a: Entity Relationship Diagrams Step 4
reader
first_name
last_name
age
Worksheet Exercise 2a: Entity Relationship Diagrams Step 5
reader
first_name
last_name
age
book
num_of_pages
id
title
author
has_genre
genre
name
recommended_age
check_out
day_check_out
Worksheet Exercise 2a: Entity Relationship Diagrams Solution
reader
first_name
last_name
age
book
num_of_pages
id
title
author
has_genre
genre
name
recommended_age
check_out
day_check_out
Worksheet Exercise 2b
Worksheet Exercise 2b: Entity Relationship Diagrams Solution
CREATE TABLE Checkouts (
day_check_out VARCHAR(10),
book_id INT REFERENCES Books,
reader_email VARCHAR(50) REFERENCES Readers,
PRIMARY KEY (book_id, reader_email, day_check_out)
);
CREATE TABLE Readers (
email VARCHAR(50) PRIMARY KEY,
first_name VARCHAR(20),
last_name VARCHAR(20),
age INT
);
CREATE TABLE Books (
id INT PRIMARY KEY,
title VARCHAR(100),
author VARCHAR(50),
genre VARCHAR(20) NOT NULL REFERENCES Genres,
num_pages INT
);
CREATE TABLE Genres (
name VARCHAR(20) PRIMARY KEY,
recommended_age INT
);
Convert the ER diagram to a series of CREATE TABLE statements. Include primary key and foreign key statements.
Worksheet Exercise 3
Worksheet Exercise 3: Subclassing Overview
Read the following scenario and draw the E/R diagram representing the relationships between the entities:
Worksheet Exercise 3: Subclassing Step 1
Read the following scenario and draw the E/R diagram representing the relationships between the entities:
Pets
name
age
color
breed
Worksheet Exercise 3: Subclassing Step 2
Read the following scenario and draw the E/R diagram representing the relationships between the entities:
Pets
name
age
color
breed
Is a
Dogs
num_barks
Worksheet Exercise 3: Subclassing Step 3
Read the following scenario and draw the E/R diagram representing the relationships between the entities:
Pets
name
age
color
breed
Is a
Dogs
Cats
num_barks
num_purrs
Functional Dependencies
Review: Functional Dependency
A → B
Indicates that attribute A determines attribute B (B is dependent on A).
Some examples:
Review: Transitive Dependency
If A → B and B → C
then A → C
{A}+ = Closure of attribute A: Set of all attributes that can be determined by A.
{A}+ = {ABC}
Functional Dependency Example: Overview
Student(studentID, name, dateOfBirth, phoneNumber)
studentID | name | dateOfBirth | phoneNumber |
1234 | Allison | 01-09-1999 | 253-876-1028 |
1235 | Ben | 03-10-2000 | 206-999-1923 |
1236 | Chris | 05-23-1999 | 206-127-1010 |
1234 | Allison | 01-09-1999 | 253-307-1678 |
Functional Dependency Example: Questions
Do the following FDs hold for�this relation?
{studentID} → {name}
{studentID} → {name, dateOfBirth}
{studentID} → {phoneNumber}
studentID | name | dateOfBirth | phoneNumber |
1234 | Allison | 01-09-1999 | 253-876-1028 |
1235 | Ben | 03-10-2000 | 206-999-1923 |
1236 | Chris | 05-23-1999 | 206-127-1010 |
1234 | Allison | 01-09-1999 | 253-307-1678 |
Functional Dependency Example: FD 1
Do the following FDs hold for�this relation?
{studentID} → {name}
{studentID} → {name, dateOfBirth}
{studentID} → {phoneNumber}
studentID | name | dateOfBirth | phoneNumber |
1234 | Allison | 01-09-1999 | 253-876-1028 |
1235 | Ben | 03-10-2000 | 206-999-1923 |
1236 | Chris | 05-23-1999 | 206-127-1010 |
1234 | Allison | 01-09-1999 | 253-307-1678 |
Functional Dependency Example: FD 2
Do the following FDs hold for�this relation?
{studentID} → {name}
{studentID} → {name, dateOfBirth}
{studentID} → {phoneNumber}
studentID | name | dateOfBirth | phoneNumber |
1234 | Allison | 01-09-1999 | 253-876-1028 |
1235 | Ben | 03-10-2000 | 206-999-1923 |
1236 | Chris | 05-23-1999 | 206-127-1010 |
1234 | Allison | 01-09-1999 | 253-307-1678 |
Functional Dependency Example: FD 3
Do the following FDs hold for�this relation?
{studentID} → {name}
{studentID} → {name, dateOfBirth}
{studentID} → {phoneNumber}
There are two tuples that agree on studentID but don’t agree on phoneNumber!
studentID | name | dateOfBirth | phoneNumber |
1234 | Allison | 01-09-1999 | 253-876-1028 |
1235 | Ben | 03-10-2000 | 206-999-1923 |
1236 | Chris | 05-23-1999 | 206-127-1010 |
1234 | Allison | 01-09-1999 | 253-307-1678 |