2 Relational Model Intro
2 Relational Model Intro
to Database Systems
The Relational Model
Instructor: Prof. Nosayba El-Sayed
Spring 2025
Good Morning(ish)!
Today’s Agenda…
5
What do we mean by a “data model”?
▪ Every DBMS is based on some data model:
a notation for describing data, including
• the structure of the data
• constraints on the content of the data
• operations on the data
6
But first… note today’s worksheet page3
7
We’re interested in the relational data
model
▪ Main concept is a “relation.”
Based on the concept of relations in math.
▪ Can think of as tables of rows and columns.
Teams Name Home Field Coach
Rangers Runnymede CI Tarvo Sinervo
Ducks Humber Public Maeve Mahar
Tom Cole
Choppers High Park
9
Example
▪ Example of a mathematical relation
– Let A = {p, q, r, s}, B = {1, 2, 3} and C = {100, 200}.
– R = {<q, 2, 100>, <s, 3, 200>, <p, 1, 200>}
is a relation on A, B, C.
tuple/row
▪ Our database tables are relations too.
▪ Example
Games Home team Away team Home goals Away goals
Rangers Ducks 3 0
Ducks Choppers 1 1
Rangers Choppers 4 2
Choppers Ducks 0 5
10
Example
▪ Example of a mathematical relation
– Let A = {p, q, r, s}, B = {1, 2, 3} and C = {100, 200}.
– R = {<q, 2, 100>, <s, 3, 200>, <p, 1, 200>}
is a relation on A, B, C.
tuple/row
▪ Our database tables are relations too.
▪ Example
{<Rangers, Ducks, 3, 0>, <Ducks, Choppers, 1, 1>,
<Rangers, Choppers, 4, 2>, <Choppers, Ducks, 0, 5>}
11
Relation schemas vs instances
▪ Schema: definition of the structure of the relation.
▪ Example:
-Teams have 3 attributes: name, home field, coach.
-No two teams can have the same name.
▪ Notation for expressing a relation’s schema
Teams(Name, HomeField, Coach)
12
Terminology
Name Home Field Coach
Teams
Rangers Runnymede CI Tarvo Sinervo
Ducks Humber Public Maeve Mahar
Tom Cole
Choppers High Park
▪ relation (table)
▪ attribute (column)
Optionally, we can specify that attributes have domains; like
types in a programming language
▪ tuple (row)
▪ arity of a relation: number of attributes (columns)
▪ cardinality of a relation: number of tuples (rows)
13
Relations are sets
▪ A relation is a set of tuples, which means:
– there can be no duplicate tuples
14
Database schemas and instances
15
Superkeys
▪ Superkey: a set of one or more attributes whose combined
values are unique:
– I.e., no two tuples can have the same values
on all of these attributes.
▪ Example:
– A relation called Course, with attributes: department code, course
number, and course name.
– One tuple might be
<“cs”, “377”, “Introduction to Databases”>
– What is a superkey for this relation?
▪ Questions..
– Does every relation have a superkey?
– Can a relation have more than one superkey?
16
Superkeys
▪ Superkey: a set of one or more attributes whose combined
values are unique:
– I.e., no two tuples can have the same values
on all of these attributes.
▪ Example:
– A relation called Course, with attributes: department code, course
number, and course name.
– One tuple might be
<“cs”, “377”, “Introduction to Databases”>
– What is a superkey for this relation?
▪ Questions..
– Does every relation have a superkey? (yes)
– Can a relation have more than one superkey? (yes)
17
Keys
▪ Key: a minimal superkey.
– I.e., you may not remove an attribute from a key, and still have
a set of attributes whose combined values are unique.
19
Example: Movies schema
20
Example: Movies schema
21
References between relations
▪ Relations often refer to each other.
▪ Example:
In the Roles relation, the tuple about Han Solo needs to say he is played
by Ford.
▪ Rather than repeat information already in the Artists table, we store
Ford’s key.
22
References between relations
Q: If aID is a key for Artists, does that mean a particular aID can
appear only once in Roles?
23
Foreign keys
▪ If the referring attribute refers to a key attribute in
another table, it is called a foreign key
Roles[aID] ⊆ Artists[aID]
25
Referential integrity constraints
▪ These R1[X] ⊆ R2[Y] relationships are called referential
integrity constraints or inclusion dependencies.
▪ Not all referential integrity constraints are foreign key
constraints.
▪ For example, we could say
Artists[aID] ⊆ Roles[aID]
▪ Notice: we are not referring to a unique tuple.
26
Figuring out integrity constraints is part
of the process: designing a schema
▪ Mapping from the real world to a relational schema is
surprisingly challenging and interesting.
▪ There are always many possible schemas.
▪ Two important goals:
1- Represent the data well.
For example, avoid constraints that prevent expressing things that
occur in the domain.
2- Avoid redundancy.
▪ (Later, we’ll learn some elegant theory that provides sound
principles for good design…)
27
Exercise (Worksheet)
Time!
1. What is the cardinality of relation Movies?
6. Does any actor show up in relation Roles twice with same mID?
7. According to the schema, can an actor show up in relation Roles twice with same
mID?
8. According to the schema, is there any limit on the number of directors a movie can
have?
9. According to the schema, can exactly the same movie title be used for two
different movies?
FAQs
▪ Movies Schema: “Is there a limit to the # of directors a
movie can have?”
o Can’t we just add a new tuple for the same movie, only with
different director names?