0% found this document useful (0 votes)
7 views

Bemm459j Week 2

Uploaded by

nofenak616
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)
7 views

Bemm459j Week 2

Uploaded by

nofenak616
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/ 36

The relational model

Basic elements

Juan Rendon, Ph.D.


[email protected]

SITE – University of Exeter

2022
What we will cover in this session

Basic concepts of the relational model.


(We will start drawing simple data models)
A problem:
Facilitate the study of films (comparisons by genre or individually).

The idea:
Build an (visualisation) solution to facilitate the exploration of films.
Initial steps:

– Gathering requirements with experts and users who are going to


use the application:
– ”We should be able to compare films. I want to see if the number of
adventure films has changed particularly in certain epochs. Every film
has a year and a major genre, although there are some films without
classification”
Initial steps:

– Draft a model:
– Of an solution (application).
– Of a database.
Use cases are part of the modelling of solutions

Sample use case:

Display the number of films of a certain genre in a range of years

Main Success Scenario:


1. The user inputs a genre and a range of years.
2. The system displays a bar-chart of the number of films made per year
within the range of dates.
A draft of a database to support the application

We should support in our database:


– Films
– Year of the films
– Film genres
A draft of a database to support the application

We should support in our database:


– Films
– Year of the films
– Film genres
How do we design an initial data model?
The relational model allows us to concentrate on
the logical view of the data rather than the
details of its storage
Table Film
.

FILM ID FILM TITLE FILM YEAR START GENRE ID


tt0031 All at Sea 1940 CM
tt0032 Gambling on the High Seas 1940 AC
tt0033 Mystery Sea Raider 1940 DR
tt0037 Saps at Sea 1940 CM
tt0039 The Sea Hawk 1940
tt0023 Social Sea Lions 1940 CM

.
Table Film
.

Attributes
FILM ID FILM TITLE FILM YEAR START GENRE ID
tt0031 All at Sea 1940 CM
tt0032 Gambling on the High Seas 1940 AC
tt0033 Mystery Sea Raider 1940 DR
tt0037 Saps at Sea 1940 CM
tt0039 The Sea Hawk 1940
tt0023 Social Sea Lions 1940 CM

.
Table Film
.

Attributes
FILM ID FILM TITLE FILM YEAR START GENRE ID
tt0031 All at Sea 1940 CM
tt0032 Gambling on the High Seas 1940 AC
tt0033 Mystery Sea Raider 1940 DR
tt0037 Saps at Sea 1940 CM
tt0039 The Sea Hawk 1940
tt0023 Social Sea Lions 1940 CM

Tuples
.
Table Genre

GENRE ID GENRE NAME


CM Comedy
AC Action
DR Drama
DC Documentary
Characteristics: perceived as a two dimensional structure
.

FILM ID FILM TITLE FILM YEAR START GENRE ID


tt0031 All at Sea 1940 CM
tt0032 Gambling on the High Seas 1940 AC
tt0033 Mystery Sea Raider 1940 DR
tt0037 Saps at Sea 1940 CM
tt0039 The Sea Hawk 1940
tt0023 Social Sea Lions 1940 CM

.
Characteristics: each row describes a single entity occurrence
.

FILM ID FILM TITLE FILM YEAR START GENRE ID


tt0031 All at Sea 1940 CM
tt0032 Gambling on the High Seas 1940 AC
tt0033 Mystery Sea Raider 1940 DR
tt0037 Saps at Sea 1940 CM
tt0039 The Sea Hawk 1940
tt0023 Social Sea Lions 1940 CM

Each row in table Film describes a single entity occurrence:


a single film.
.
Characteristics: each column represents an attribute and has a distinct
name
.

FILM ID FILM TITLE FILM YEAR START GENRE ID


tt0031 All at Sea 1940 CM
tt0032 Gambling on the High Seas 1940 AC
tt0033 Mystery Sea Raider 1940 DR
tt0037 Saps at Sea 1940 CM
tt0039 The Sea Hawk 1940
tt0023 Social Sea Lions 1940 CM

.
Characteristics: all values in a column match the the attribute
characteristics
.

the column FILM YEAR START is of integer type

FILM ID FILM TITLE FILM YEAR START GENRE ID


tt0031 All at Sea 1940 CM
tt0032 Gambling on the High Seas 1940 AC
tt0033 Mystery Sea Raider 1940 DR
tt0037 Saps at Sea 1940 CM
tt0039 The Sea Hawk 1940
tt0023 Social Sea Lions 1940 CM

.
Characteristics: The column’s range of permissible values is known as
domain
.

FILM YEAR START > 0?

FILM ID FILM TITLE FILM YEAR START GENRE ID


tt0031 All at Sea 1940 CM
tt0032 Gambling on the High Seas 1940 AC
tt0033 Mystery Sea Raider 1940 DR
tt0037 Saps at Sea 1940 CM
tt0039 The Sea Hawk 1940
tt0023 Social Sea Lions 1940 CM

.
Characteristics: the order of rows does not affect the user
.

FILM ID FILM TITLE FILM YEAR START GENRE ID


tt0031 All at Sea 1940 CM
tt0032 Gambling on the High Seas 1940 AC
tt0033 Mystery Sea Raider 1940 DR
tt0037 Saps at Sea 1940 CM
tt0039 The Sea Hawk 1940
tt0023 Social Sea Lions 1940 CM

.
Characteristics: each table must have a primary key
.

FILM ID uniquely identifies each film

FILM ID FILM TITLE FILM YEAR START GENRE ID


tt0031 All at Sea 1940 CM
tt0032 Gambling on the High Seas 1940 AC
tt0033 Mystery Sea Raider 1940 DR
tt0037 Saps at Sea 1940 CM
tt0039 The Sea Hawk 1940
tt0023 Social Sea Lions 1940 CM

.
But it can have others. For example, a secondary key
.

FILM TITLE could be a secondary key

FILM ID FILM TITLE FILM YEAR START GENRE ID


tt0031 All at Sea 1940 CM
tt0032 Gambling on the High Seas 1940 AC
tt0033 Mystery Sea Raider 1940 DR
tt0037 Saps at Sea 1940 CM
tt0039 The Sea Hawk 1940
tt0023 Social Sea Lions 1940 CM

It can help narrowing down a search, although


several films could have the same name.
.
But it can have others. For example, a secondary key
.

FILM YEAR START could be a secondary key

FILM ID FILM TITLE FILM YEAR START GENRE ID


tt0031 All at Sea 1940 CM
tt0032 Gambling on the High Seas 1940 AC
tt0033 Mystery Sea Raider 1940 DR
tt0037 Saps at Sea 1940 CM
tt0039 The Sea Hawk 1940
tt0023 Social Sea Lions 1940 CM

But we could have hundreds of results in a search.


.
Small database
.

FILM ID FILM TITLE FILM YEAR START GENRE ID


tt0031 All at Sea 1940 CM
tt0032 Gambling on the High Seas 1940 AC
tt0033 Mystery Sea Raider 1940 DR
tt0037 Saps at Sea 1940 CM
tt0039 The Sea Hawk 1940
tt0023 Social Sea Lions 1940 CM

.
Small database
.
GENRE ID GENRE NAME
CM Comedy
AC Action
DR Drama
DC Documentary

FILM ID FILM TITLE FILM YEAR START GENRE ID


tt0031 All at Sea 1940 CM
tt0032 Gambling on the High Seas 1940 AC
tt0033 Mystery Sea Raider 1940 DR
tt0037 Saps at Sea 1940 CM
tt0039 The Sea Hawk 1940
tt0023 Social Sea Lions 1940 CM

.
Small database
.
GENRE ID GENRE NAME
CM Comedy
Primary key:
AC Action GENRE ID;
DR Drama Foreign key: None.
Primary key: DC Documentary
FILM ID;
Foreign key:
GENRE ID

FILM ID FILM TITLE FILM YEAR START GENRE ID


tt0031 All at Sea 1940 CM
tt0032 Gambling on the High Seas 1940 AC
tt0033 Mystery Sea Raider 1940 DR
tt0037 Saps at Sea 1940 CM
tt0039 The Sea Hawk 1940
tt0023 Social Sea Lions 1940 CM

.
Small database – UML representation

FILM
FILM ID GENRE
FILM TITLE GENRE ID
FILM YEAR START GENRE NAME
GENRE ID
Small database – UML representation

FILM
FILM ID GENRE
FILM TITLE is of I GENRE ID
FILM YEAR START 0..1 GENRE NAME
GENRE ID
Small database – UML representation

FILM
FILM ID GENRE
FILM TITLE is of I GENRE ID
FILM YEAR START 0..* 0..1 GENRE NAME
GENRE ID
Small database – UML representation

FILM
FILM ID {PK} GENRE
FILM TITLE is of I GENRE ID {PK}
FILM YEAR START 0..* 0..1 GENRE NAME
GENRE ID {FK1}
Small database – UML representation
GENRE
GENRE ID {PK}
GENRE NAME

0..1

N
is of

0..*
FILM
FILM ID {PK}
FILM TITLE
FILM YEAR START
GENRE ID {FK1}
Small database
Tables UML diagram
.
GENRE ID GENRE NAME
CM Comedy GENRE
Primary key:
AC Action GENRE ID; GENRE ID {PK}
DR Drama Foreign key: None. GENRE NAME
Primary key: DC Documentary
FILM ID; 0..1
Foreign key:
GENRE ID
N
FILM ID FILM TITLE FILM YEAR START GENRE ID is of
tt0031 All at Sea 1940 CM
tt0032 Gambling on the High Seas 1940 AC 0..*
tt0033 Mystery Sea Raider 1940 DR FILM
tt0037 Saps at Sea 1940 CM FILM ID {PK}
tt0039 The Sea Hawk 1940 FILM TITLE
FILM YEAR START
tt0023 Social Sea Lions 1940 CM
GENRE ID {FK1}
.
Let’s give it a try with this use case:

Display the number of paintings by an artist during her


career

Main Success Scenario:


1. The user chooses an artist.
2. The system displays the line plot of the number of
paintings by that artist.

Requirement: Every painting has an author and each painter can create one or
more paintings.
Another exercise. Imagine the following use case:

Display yearly average Co2 emissions for all countries

Main Success Scenario:


1. A decision maker selects an option to view Co2 emis-
sions.
2. The system displays all countries and their total yearly
Co2 emissions for the past 10 years in a line plot.

Requirement: Each country has yearly total emission measurements of Co2.


One possible solution

EMISSION
COUNTRY EMISSION ID {PK}
COUNTRY ID {PK} has I COUNTRY ID {FK1}
COUNTRY NAME 1..1 0..* YEAR EMISSION
QUANTITY EMISSION
Readings

Chapter 2 of

Connolly, T., Begg, C. E. and Holowczak, R. (2008). Business


Database Systems. Addison-Wesley.

You might also like