Beruflich Dokumente
Kultur Dokumente
Surnam
e
1042
Jones
1043
1044
First
name
D.O.B.
Addres
s
Phone
number
Emma
05/04/95
123 High
Street
01234
765555
Smith
Louise
12/08/95
45 Low
Road
01234
688674
White
Simon
26/06/95
67
Middle
Lane
01234
984532
File collection of
related records
Illnesse
s
Allergie
s
Nuts
Diabetes
Doctor
Dr.
Brown
Dr.
Green
Wasp
stings
Dr.
Yellow
Continued
What is a key field?
A unique piece of data in a record also known as
a
primary key.
What is a flat file database?
A database which consists of only one table.
What is a relational database?
A database which consists of more than one
table.
Continued
ID
Title
Director
Lead Actor
Certificate
01
Frank Darabont
Tim Robbins
15
02
The Godfather
Marlon Brando
15
03
Inception
Christopher Nolan
Leonardo DiCaprio
12A
04
Pulp Fiction
Quentin Tarantino
John Travolta
18
05
Schindler's List
Steven Spielberg
Liam Neeson
15
Primary Key
Suitable or Not
In your books write down whether or not each of
the
following would be suitable primary keys?
Not
Date of BirthSuitable
Suitabl
Employee Number
e
Suitabl
Student IDe
Not
Surname Suitable
Not
Postcode Suitable
Suitabl
Car Number Plate
e
e
l
i
F
t
a
l
F
e
l
t
p
n
e
m
d
a
If students
are in the
u
x
t
E
S
same
tutor
group which
e
e
s
e
fields
would contain data
a
S
b
a
that would be repeated?
t
a
D
Student
Number
Surname
Forename
Date of Birth
Tutor Group
Staff Number
Staff Title
Staff Initial
Staff Surname
Linking Tables
In relational databases the same data is stored
more efficiently in more than one table. These
tables are linked together.
This helps save time as you no longer need to type
in the
same data over
and over Tutor
again known
as
Student
Tutors
Students
Groups
Student
reducing
data redundancy.
Staff
Student
Number
Number
Tutor Group
Number
Surname
Surname
Staff Number
Staff Title
Forename
Forename
Staff Initial
Date of Birth
Date of Birth
Tutor Group
Tutor Group
Staff
Surname
Staff Number
Staff Title
Staff Initial
Tutor Surname
Relationships
To link tables together there needs to be
the same field in each table, which is
usually the primary key.
Students
Student
Number
Surname
Forename
Date of Birth
Tutor Group
Tutor
Groups
Tutor Group
Staff
Number
Tutors
Staff Number
Staff Title
Staff Initial
Staff
Surname
Foreign Keys
A foreign key is the primary key of another table.
Foreign keys are used to establish relationships between tables.
In the example the field Tutor Group would be the key field or
primary key in the Tutor Groups table and a foreign key in the
Students table.
Students
Student
Number
Surname
Forename
Date of Birth
Tutor Group
Foreign
Tutor
Groups
Tutor Group
Staff
Number
Primary
Key
Relationships
Primary Keys
Students
Tutor
Groups
Student
Number
Tutor Group
Surname
Staff ID
Staf
t
n
e
e
d
s
u
a
t
b
S
Which
are the ta
e
a
e
foreign
keys?
D
S
l
a
n
e
l
o
i
p
t
a
m
l
a
x
Re
E
Forename
Date of Birth
Tutor Group
Staff ID
Staff Title
Staff Initial
Staff
Surname
Task
Create the database structure for a DVD Rental Shop.
You will need to store the following information and assign
appropriate primary and foreign keys.
Length of Film Forename
Year Released Film Title
E-mail
Date Rented
Rating
Address
Rental Price
Age
Surname Date Returned
Phone Number Film Genre
Gender Postcode
Step 1 Divide the fields up into separate categories there
will be 3 tables.
The Tables
Customer
Rentals
Film
Surname
CustomerID
RentalID
Date
Rented
Film
Title
FilmID
Forename
Surname
Rented
Date Returned
Rating
Film Title
Address
Forename
Date Returned
Film
Genre
Rating
Postcode
Address
Date
Released
Film Genre
Telephone
Postcode
Number
Telephone
Length
of Film
Date Released
E-mail
Number
Age
E-mail
Gender
Age
Rental
LengthPrice
of Film
Rental Price
Gender
Rentals
Film
CustomerID
RentalID
FilmID
Surname
Date Rented
Film Title
Forename
Date Returned
Rating
Address
Film Genre
Postcode
Date Released
Telephone
Number
Length of Film
Rental Price
Age
Gender
Rentals
Film
CustomerID
RentalID
FilmID
Surname
Date Rented
Film Title
Forename
Date Returned
Rating
Address
CustomerID
Film Genre
Postcode
FilmID
Date Released
Telephone
Number
E-mail
Length of Film
Rental Price
Age
Gender
Customer
Surname
CustomerID
RentalID
Forename
Surname
Date Rented
Address
Forename
Postcode
Address
Telephone Number
Postcode
E-mail
Age
Telephone
Number
Gender
Date Rented
Age
Date Returned
Film
Rentals
Date Returned
CustomerID
FilmID
FilmID
Film Title
Rating
Film Genre
Date Released
Length of Film
Rental Price
Gender
Film Title
Rating
Film Genre
Date Released
Length of Film
Rental Price
Creating a database
Have a go at creating the Rental
database...
Your teacher will show you how to:
Create database tables
Add fields
Assign appropriate data types
Dont include the Gender field in the
Customer table.
We will add foreign keys later.
Rentals
Film
CustomerID
RentalID
FilmID
Surname
Date Rented
Film Title
Forename
Date Returned
Rating
Address
Film Genre
Postcode
Date Released
Telephone
Number
Length of Film
Rental Price
E-mail
Age
Types of Relationships
There are 2 types of relationships:
One-to-One
One-to-Many
One-to-One
A one-to-one relationship might be better
explained with the example of couple A
husband and a wife.
A husband can only have one wife.
A wife can only have one husband.
Husban
d
Wife
One-to-Many
Think about a mother and her children.
A mother can have many children.
A child can only have one biological mother.
Mother
Many
Symbol
Child
Rentals
Film
CustomerID
RentalID
FilmID
Surname
Date Rented
Film Title
Forename
Date Returned
Rating
Address
CustomerID
Film Genre
Postcode
FilmID
Date Released
Telephone
Number
Length of Film
E-mail
Age
Rental Price
From scratch
Create a database structure.
You will need to:
Create tables and add fields to each table
Assign appropriate data types
Create one-to-one/one-to-many
relationships as appropriate for the system
Answer
Plenary Exam
Questions
Give three features of a relational
database that are not found in a
flat file database.
Three from:
[3 marks]
Plenary Exam
Questions
Explain the benefits of using a relational
database over flat file database. [2
marks]
Two from:
Review Objectives
By the end of this lesson you will be able to:
1. Assign appropriate primary keys/key fields
2. Identify foreign keys in different
tables/files
3. Describe the key term relationships
4. Create relational databases