Relational Databases (AQA GCSE Computer Science)

Revision Note

Robert Hampton

Expertise

Computer Science Content Creator

Relational Databases

What is a database?

  • A Database is a structured, persistent 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
  • There are two main types of database
    • Flat file
    • Relational

Flat file 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
  • 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

Relational database

  • 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
  • A relational database solves the issues in a flat file database:

    • 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

Tables & Records

What is a table?

  • A table is a complete set of records about the same subject/topic in a database

cars

car_id make model colour price
1 Peugeot 2008 Red 24950
2 Mazda MX5 Blue 17995
3 Citroen DS4 Black 21450
4 Ford Puma White 19500

  • An example of a database table named cars

What is a record?

  • A record is complete set of fields on a single entity in a table (row)

cars

car_id make model colour price
1 Peugeot 2008 Red 24950
2 Mazda MX5 Blue 17995
3 Citroen DS4 Black 21450
4 Ford Puma White 19500

  • An example of a record in the cars table

Fields & Data Types

What is a field?

  • A field is a single piece of data in a table (column)

cars

car_id make model colour price
1 Peugeot 2008 Red 24950
2 Mazda MX5 Blue 17995
3 Citroen DS4 Black 21450
4 Ford Puma White 19500

  • An example of a field in the cars table

What is a data type?

  • A data type is the type of data that can be held in a field and is defined when designing a table
  • Examples of common datatypes are:
    • Numeric - whole/decimal
    • Character/string - text data
    • Date/Time 
    • Boolean - true or false values
  • In the car table above, the following datatypes would be used:
    • car_id: numeric
    • make: string
    • model: string
    • colour: string
    • price: numeric 

Primary Keys & Foreign Keys

What is a primary key?

  • A primary key is a unique field that can be used to identify a record in a table
  • order_id is the primary key for the orders table

visualising-a-database

  • customer_id is the primary key for the customers table

What is a foreign key?

  • A foreign key is a field in a table that refers to the primary key in another table.
  • A foreign key is used to link tables and create relationships
  • 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

Key database terminology

Term Definition
Table A collection of records with a similar structure
Record A group of related fields, representing one data entry
Field A single piece of data in a record
Data type Type of data held in a field
Primary key A unique identifier for each record in a table. Usually an ID number
Foreign key A field in a table that refers to the primary key in another table. Used to link tables and create relationships

Worked example

A relational database has been developed for a dance club to store information about their members and the styles of dance they practice.

The database contains two tables: Members and Styles

Figure A shows some data from the tables. 

Members

MemberID FirstName LastName DateJoined
1 Zarmeen Hussain 2024-01-19
2 Fyn Ball 2024-02-01
3 George Johnson 2024-02-25
4 Ella Franks 2024-03-04


Styles

StyleID MemberID Style DateStarted
1 1 Hip Hop 2024-01-22
2 1 Ballroom 2024-02-13
3 3 Contemporary 2024-03-01
4 2 Street 2024-03-07

(a) State one benefit of using relational databases [1]

(b) State the name of the field from the Members table that is the most suitable to use as the primary key [1]

(c) State the name of the field from the Styles table that is a foreign key [1]

Answers

  • (a) reduces data redundancy // reduces data inconsistency
  • (b) MemberID
  • (c) MemberID

Guidance

  • Ignore case (b, c)
  • No mark if inside quotation marks (b, c)
  • No mark if obvious space in response (b, c)

You've read 0 of your 0 free revision notes

Get unlimited access

to absolutely everything:

  • Downloadable PDFs
  • Unlimited Revision Notes
  • Topic Questions
  • Past Papers
  • Model Answers
  • Videos (Maths and Science)

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

the (exam) results speak for themselves:

Did this page help you?

Robert Hampton

Author: Robert Hampton

Rob has over 16 years' experience teaching Computer Science and ICT at KS3 & GCSE levels. Rob has demonstrated strong leadership as Head of Department since 2012 and previously supported teacher development as a Specialist Leader of Education, empowering departments to excel in Computer Science. Beyond his tech expertise, Robert embraces the virtual world as an avid gamer, conquering digital battlefields when he's not coding.