You are on page 1of 16

Relational Database

Objectives
 Evaluate the difference between a flat file and a relational
database and why one might be preferred in certain situations.

 Create a relational database.


Flat file database

When you first set up your database, you can choose to make a 'flat-
file' database or a 'relational' database.

With a flat file database, all your data is stored in one large table.

Take a database that a vet might use. In our example on the right,
there is data about the owner of the pet i.e. name, address, phone
number, there is data about the pet - name, type of animal, date of
birth, and there is also data about any appointments the pet has.
Flat file database

• Every single time the pet has an appointment, the customer's title, surname,
street, town, county, and phone number must be entered. Also, the pet's
name, type and d.o.b. also must be entered.

• That would get tiresome having to enter so much data each time and there
would be a great risk of making a mistake - remember GIGO.

• Repeating data unnecessarily like this is called 'data duplication'.


Relational databases
On the previous slide, we saw that a flat file database wasn't always the best
choice as it causes a lot of data duplication.

The answer to this is called a relational database.

In the database below, the data is split up into sensible groups i.e. customer
data, pet's data and appointments data. Then a separate table is made for each
group.
Relational databases
Once the tables have been set up, a relationship can be created to link them
together - as shown by the lines linking the tables below.

This is known as a 'relational database'.


Relational databases
A foreign key is used to link tables together and create a relationship. It is a field in
one table that is linked to the primary key in another table.

The primary key in the Artists table is: ArtistID


The primary key in the Genre table is: GenreID
These primary keys link to identically named fields in the Recordings table. Each of
those identically named fields are known as a 'foreign key'
 
Relational databases
The main benefit of a relational database is that data doesn't have to be
duplicated.

When a customer books an appointment for their pet, a new record is created
on the 'appointment's table' and the relevant Customer and Pet IDs are chosen.

Reducing data duplication reduces the amount of data which needs to be


stored, thus making the database smaller.

It also reduces the risk of mistakes, because every time you must type the same
data in, there is a risk you could mis-spell it.
Plenary
Car
Learner
Lesson
LearnerID(PK)
LessonID(PK) Registration(PK)
Forename
LessonDate Make
Surname
TimeSlotStart Model
Telephone
Registration(PK) RegYear
LearnerID(FK) Transmission
Salesperson Table Products Table
SalesPersonID(PK) ProductID(PK)
FirstName ProductName
Shop NoOfProducts
Manufacturer
SalesPersonID(FK)

You might also like