Relational Databases (OCR A Level Computer Science)

Revision Note

Neil Southin

Written by: Neil Southin

Reviewed by: James Woodhouse

Relational Databases

What is a Database?

  • A Database is an organised collection of data

  • It allows easy storage, retrieval, and management of information

  • Electronic databases offer a number of key benefits:

    • Easier to add, delete, modify and update data

    • Data can be backed up and copied easier

    • Multiple users, from multiple locations, can access the same database at the same time

Database Terminology

Term

Definition

Field

A single piece of data in a record

Record

A group of related fields, representing one data entry

Table

A collection of records with a similar structure

Primary key

A unique identifier for each record in a table. Usually an ID number

Compound primary key
(sometimes called composite)

A combination of (2 or more) fields that is unique for all records

Foreign key

A field in a table that refers to the primary key in another table. Used to link tables and create relationships

Secondary key

A field or fields that are indexed for faster searching

Database Management System
(DBMS)

Software used to manage databases. Examples include MySQL, Oracle, Microsoft SQL Server, PostgreSQL

Primary, Foreign & Secondary Keys

Visualising a database

visualising-a-database
  • This database has 2 tables : orders and customers

  • Fields:

    •  In the orders table are order_id, product, total and customer_id

    • In the customers table are customer_id, first_name, last_name, phone and country

  • A record would be 1 complete row in either table

  • order_id is the primary key for the orders table
    customer_id is the primary key for the customers table

  • In the orders table customer_id is a foreign key - it links an order back to the customer that made the order in the customer table

Indexing (Secondary Keys)

  • Indexing is a technique used to speed up data retrieval in a database

  • It works in a similar way to the index in a book 

  • If a student had a maths book and wanted to find the section on factorising, they could start at the first page and look at each page in turn until they found the section they wanted 

  • But this would be slow, so it is better to look in the index  to find where the factorising section is and just go directly to it 

  • Likewise in a database, certain columns can be indexed so that the DBMS does not have to look at every single record during a search and can just go to the relevant records directly 

  • This can greatly speed up searches 

  • Fields that are indexed are known as secondary keys

Flat File vs Relational Database

  • A flat file database is one that stores all data in a single table

  • It is simple and easy to understand but causes data redundancy, inefficient storage and is harder to maintain

  • A relational database is one that organises data into multiple tables 

  • It uses keys to connect related data which reduces data redundancy, makes efficient use of storage and is easier to maintain

Consider this example flat file table of students 

flat-file-table
  • This table has redundant data - the tutor and form room information repeats 

  • This is inefficient

  • If a tutor changed their name we would need to find all instances of that name and change them all

  • Missing any would mean the table had inconsistent data

A relational database would solve this issue:

  • A new table could be created to store the tutor information and the tutor information in the student table could be moved to the new table.  Then a foreign key in the student table (TutorID) could link a student to their tutor

relational-database
  • Now the name of each tutor and their form room is stored only once

  • This means if they change only one piece of data, the data is updated in the entire database and Inconsistency is avoided

Worked Example

Customers’ details are stored in the flat file database table Customer. An extract of the table is shown below

worked-example

Describe one problem that would arise with the flat file database structure if a customer wanted to insure more than one car at the same time

[2]

Answer:

 One mark per pair:

Only one customer entry allowed (because of key field)... 

  so would not be able to add second entry [1]

Customer data already present/would be repeated...

   resulting in redundant data/wasted space/inconsistencies should changes be made [1]

Last updated:

You've read 0 of your 5 free revision notes this week

Sign up now. It’s free!

Join the 100,000+ Students that ❤️ Save My Exams

the (exam) results speak for themselves:

Did this page help you?

Neil Southin

Author: Neil Southin

Expertise: Computer Science

Neil has been a passionate Computing teacher for nearly 20 years, teaching Computing and ICT in a large Sixth Form College.

James Woodhouse

Author: James Woodhouse

Expertise: Computer Science

James graduated from the University of Sunderland with a degree in ICT and Computing education. He has over 14 years of experience both teaching and leading in Computer Science, specialising in teaching GCSE and A-level. James has held various leadership roles, including Head of Computer Science and coordinator positions for Key Stage 3 and Key Stage 4. James has a keen interest in networking security and technologies aimed at preventing security breaches.