3.2 Databases
3.2 Databases
Science
3.2 Databases
Contents
Relational Databases
Data Normalisation
Entity Relationship Diagrams
Capturing, Selecting, Managing & Exchanging Data
SQL
Referential Integrity
Transaction Processing
© 2025 Save My Exams, Ltd. Get more and ace your exams at [Link] 1
Relational Databases
Your notes
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
Compound primary A combination of (2 or more) fields that is unique for all records
key
(sometimes called
composite)
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
© 2025 Save My Exams, Ltd. Get more and ace your exams at [Link] 3
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
Your notes
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
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:
© 2025 Save My Exams, Ltd. Get more and ace your exams at [Link] 4
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 Your notes
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
© 2025 Save My Exams, Ltd. Get more and ace your exams at [Link] 5
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
Your notes
[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]
© 2025 Save My Exams, Ltd. Get more and ace your exams at [Link] 6
Data Normalisation
Your notes
What is normalisation?
In A Level Computer Science, normalisation is the process of organising a database to
reduce data duplication and improve data accuracy and consistency
Achieved by applying a set of guidelines (forms), each with specific rules and
requirements
Enhances database efficiency and maintainability
Provides consistency within the database
© 2025 Save My Exams, Ltd. Get more and ace your exams at [Link] 7
This customers table below has a primary key and the name is stored in two fields so it is
atomic
Your notes
This table is in first normal form
© 2025 Save My Exams, Ltd. Get more and ace your exams at [Link] 8
Third Normal Form (3NF)
Your notes
What is third normal form?
For a table to be in third normal form it must:
Fulfil all 2NF requirements
Have no transitive dependencies
Non-prime attributes must not depend on other non-prime attributes
Have each non-prime attribute dependent solely on the primary key, not on other
non-prime attributes
Have separate tables for attributes with transitive dependencies, and the tables
should be linked using a foreign key
In this table below, the certificate depends on the title - this a transitive dependency and
so this table is not in third normal form
Worked Example
An airport holds details of flights in a database using the table Flight. An extract of
the table is shown below.
© 2025 Save My Exams, Ltd. Get more and ace your exams at [Link] 9
Your notes
© 2025 Save My Exams, Ltd. Get more and ace your exams at [Link] 10
Entity Relationship Diagrams
Your notes
© 2025 Save My Exams, Ltd. Get more and ace your exams at [Link] 11
The entities are drawn as boxes with the entity name in
The relationships are drawn in as what is known as ‘crow’s feet notation’ Your notes
This is how to draw the relationships in the exam:
Worked Example
An insurance company's offices have a large number of black and white printers
The company's technicians keep accurate records of the printers in the building,
and the quantity of toner cartridges in stock, in a flat file database. An extract of
the database is shown:
© 2025 Save My Exams, Ltd. Get more and ace your exams at [Link] 12
Zodiac reception Zod17 4 [Link]
ZN217 shop / Z17
Your notes
Zodiac conference had to Zod17 4 [Link].c
ZN217 Room 2 add RAM toner / LP-7XB
© 2025 Save My Exams, Ltd. Get more and ace your exams at [Link] 13
Your notes
© 2025 Save My Exams, Ltd. Get more and ace your exams at [Link] 14
Capturing, Selecting, Managing & Exchanging Data
Your notes
Capturing Data
How can data be captured?
Data can be captured by a computer in many forms, these include:
Forms
OMR (Optical Mark Recognition)
OCR (Optical Character Recognition)
Sensors
Barcodes
Data Mining
Forms
Collect user input
Organise data in structured format
Common in web applications
© 2025 Save My Exams, Ltd. Get more and ace your exams at [Link] 15
Your notes
© 2025 Save My Exams, Ltd. Get more and ace your exams at [Link] 16
Your notes
Sensors
Devices that detect and respond to changes in environment
Convert physical signals into digital data
Facilitates automated data collection and real-time monitoring
Used in various applications:
Temperature sensors
Pressure sensors
Proximity sensors
Light sensors
Motion sensors
Humidity sensors
Gas sensors
Force sensors
Acoustic sensors
Magnetic sensors
© 2025 Save My Exams, Ltd. Get more and ace your exams at [Link] 17
Your notes
© 2025 Save My Exams, Ltd. Get more and ace your exams at [Link] 18
Your notes
Selecting Data
Query By Example (QBE)
© 2025 Save My Exams, Ltd. Get more and ace your exams at [Link] 19
User-friendly method for constructing database queries using a visual interface
Allows users to search for data by providing an example of the desired output Your notes
Key Features
Visual representation: QBE uses a grid or form-based interface, where users can
enter criteria in columns representing database fields
Intuitive: Users don't need to learn complex query syntax, making it accessible for
non-technical users
Flexible: Allows for simple to complex queries, including filtering, sorting, and joining
multiple tables
How QBE Works
Users enter criteria in the appropriate columns or fields in the QBE grid or form
The QBE system translates the user's input into an equivalent SQL query or other query
language
The query is executed against the database, and the results are displayed to the user
Common Query Operations
Filtering: Users can specify conditions or criteria in the QBE grid to retrieve specific
records (e.g., all customers from a particular city)
Sorting: Users can indicate the desired sorting order for the results (e.g., ascending or
descending by last name)
Joining: Users can combine data from multiple related tables by specifying relationships
between the tables in the QBE grid
Aggregation: Users can perform calculations or summaries on the data (e.g., counting
the number of records, calculating averages, or summing values)
Benefits and Drawbacks of Query By Example (QBE)
Drawbacks
Benefits
Easy to learn and use, even for non-technical Less powerful and flexible than SQL for
users complex queries and data manipulation
Provides a more accessible way to perform Can be slower than SQL queries for large
database searches compared to writing SQL datasets or complex operations
queries
© 2025 Save My Exams, Ltd. Get more and ace your exams at [Link] 20
Managing & Exchanging Data
Your notes
Managing data
After a database has been created, there must be easy ways of being able to manage
the data, this includes:
Add new data
Edit/modify existing data
Delete data
This can be achieved by:
A database manipulation language (DML) such as SQL
Built in facilities of a Database Management System (DBMS)
Exchanging data
CSV (Comma Separated Values)
Simple data exchange format
Stores tabular data in plain text
Uses commas to separate values
Widely supported and easy to parse
© 2025 Save My Exams, Ltd. Get more and ace your exams at [Link] 21
EDI (Electronic Data Interchange)
Standardised electronic communication method Your notes
Transfers documents and data between businesses
Reduces paper usage and manual processes
Streamlines transactions and increases efficiency
Memory sticks
Portable storage devices, also known as USB flash drives or thumb drives
Use flash memory to store and transfer data between computers and other devices
Connect to devices via USB (Universal Serial Bus) port
Benefits and Drawbacks of Memory Sticks
Benefits Drawbacks
Portable: Compact size allows for easy transport Data loss risk due to physical damage,
and storage loss, or theft
Durable: No moving parts, making them resistant Slower transfer speeds compared to
to physical damage other storage solutions
© 2025 Save My Exams, Ltd. Get more and ace your exams at [Link] 22
Compatible: Widely supported across different
operating systems and devices
Your notes
Email
Electronic communication system used for exchanging messages and files between
users
Requires internet access and an email account with an email service provider
Benefits and Drawbacks of Email
Benefits Drawbacks
Fast: Allows for near-instant Limited file size: Most email service providers
communication across the world impose restrictions on attachment sizes
Versatile: Supports the attachment of Reliability: Delivery issues can occur due to
various file types and sizes server problems, incorrect email addresses, or
spam filters
© 2025 Save My Exams, Ltd. Get more and ace your exams at [Link] 23
SQL
Your notes
FROM Specifies the tables to retrieve data SELECT name, age FROM users;
from (retrieves names and ages from
the 'users' table)
© 2025 Save My Exams, Ltd. Get more and ace your exams at [Link] 24
AND Combines multiple conditions in a SELECT * FROM users
WHERE clause WHERE age > 18 AND city =
Your notes
'New York';
(retrieves users older than 18
and from New York)
WILDCARDS '*' and '%' symbols are used for SELECT * FROM users;
searching and matching data (retrieves all columns for the
'*' used to select all columns in a table 'users' table)
'%' used as a wildcard character in the
LIKE operator SELECT * FROM users WHERE
name LIKE 'J%';
(retrieves users whose names
start with 'J')
Examples
Select all the fields from the Customers table
Command:
Output:
Select the ID, name & age of customers who are older than 25
Command:
© 2025 Save My Exams, Ltd. Get more and ace your exams at [Link] 25
Output:
1 John Doe 30
3 Peter Lee 40
Select the name and country of customers who are from a country that begins with 'U'
Command:
Output:
Name Country
Jane Doe UK
Output:
Worked Example
© 2025 Save My Exams, Ltd. Get more and ace your exams at [Link] 26
Customers’ details are stored in the flat file database table Customer. An extract of
the table is shown below
Your notes
Write the SQL statement that would show only the CustomerID and Surname fields
for customers with the Title “Miss” or “Mrs”
[4]
Answer:
SELECT CustomerID, Surname [1]
FROM Customer [1]
WHERE Title="Miss" [1]
OR Title = "Mrs" [1]
Nested A select within another select SELECT * FROM users WHERE age
SELECT statement (nested). A mini select > (SELECT AVG(age) FROM users);
within the main one
(retrieves users with an age greater
than the average age)
Examples
Table: Employees
ID Name Salary Department City
© 2025 Save My Exams, Ltd. Get more and ace your exams at [Link] 27
2 Zarmeen Azra 52000 Sales Manchester
Your notes
3 Ella Stanley 39500 Marketing Birmingham
Select all fields for employees whose salary is bigger than the average salary of all
employees
Command:
Output:
Inserting Data
Example
Command Description
INSERT Adds new data to a database INSERT INTO users (name, age)
table VALUES ('John Doe',25);
(inserts a new user with the name 'John Doe'
and age 25)
Example
Table: Employees
Insert a new employee into the Employees table with the 'Name', 'Salary', 'Department'
and 'City' fields
© 2025 Save My Exams, Ltd. Get more and ace your exams at [Link] 28
Command:
Your notes
Output:
Deleting Records
Example
Command Description
Example
Table: Employees
© 2025 Save My Exams, Ltd. Get more and ace your exams at [Link] 29
4 George Rope 47250 Sales Leeds
Your notes
Delete all records from the Employees table whose department is 'Marketing'
Command:
Output:
Worked Example
A database stores information about songs on a music streaming service. One of
the tables called Song has the fields Title, Artist, Genre and Length
Write an SQL statement that will remove all songs by RandomBits from the table
Song
[2]
Answer:
DELETE FROM Song [1]
WHERE Artist = “RandomBits” [1]
Deleting Tables
Example
Command Description
© 2025 Save My Exams, Ltd. Get more and ace your exams at [Link] 30
DROP Deletes a table in a database DROP TABLE users;
(deletes the 'users' table)
Your notes
Example
Table: Employees
Output
© 2025 Save My Exams, Ltd. Get more and ace your exams at [Link] 31
Referential Integrity
Your notes
Referential Integrity
What is referential integrity?
In A Level Computer Science, referential integrity ensures consistency between related
tables in a relational database
Maintains valid relationships between primary and foreign keys
There should not be foreign keys for which a matching primary key in the linked table
does not exist
Foreign key constraints
Value in a foreign key field must either:
Match a primary key value in the related table, or
Be null (if allowed)
Enforce referential integrity
Rules:
Cascade actions
CASCADE: automatically makes changes to related records
SET NULL: sets foreign key value to null in related records
SET DEFAULT: sets foreign key value to its default in related records
NO ACTION/RESTRICT: prevents changes if related records exist
Update or delete actions will take effect everywhere in the database automatically
Types:
Benefits and drawbacks of referential integrity
Drawbacks
Benefits
© 2025 Save My Exams, Ltd. Get more and ace your exams at [Link] 32
Implement triggers to enforce custom referential integrity rules
Regularly validate and clean up data to ensure consistency Your notes
Worked Example
A hotel uses a computer system to keep track of room bookings. The hotel staff are
able to query a database to discover which rooms are booked or which rooms are
free
The hotel booking database enforces referential integrity.
Explain what is meant by the term ‘referential integrity’ and how this could
potentially be broken
[2]
Answer:
Database/relationships are consistent and each foreign key links to an existing/valid
primary key [1]
If a primary key is deleted, foreign keys that link to it are no longer valid so they should
also be deleted - this is known as a cascaded delete [1]
© 2025 Save My Exams, Ltd. Get more and ace your exams at [Link] 33
Transaction Processing
Your notes
Transaction Processing
What is a transaction?
A transaction is a sequence of database operations treated as a single unit of work
Ensures data consistency and integrity during simultaneous access
Example: money transfer between bank accounts. The transaction here would be a
withdrawal from one account and a deposit into another. Both operations must happen
together or neither should happen
Problems that arise from transaction processing
Concurrency: When multiple transactions are executed simultaneously, they might
try to access or modify the same data, leading to inconsistencies
Deadlock: This occurs when two or more transactions are waiting for each other to
release resources, causing them to wait indefinitely
Data Integrity: Transactions might leave the database in an inconsistent state if they
fail in the middle of execution
Isolation: In a multi-user environment, one user's transaction might affect another
user's transaction, leading to unpredictable outcomes
Durability: If a system fails after a transaction has been confirmed, it may result in
loss of data
Solutions to overcome problems that arise in transaction processing
Locking: Implementing a locking mechanism ensures that no two transactions can
access the same data simultaneously. There are two types of locks: shared locks
and exclusive locks
Deadlock Prevention or Deadlock Detection: Deadlocks can be prevented by
ordering the way in which resources are requested or by having a timeout
mechanism
Logging and Recovery: By keeping a log of all changes, the system can recover to a
consistent state after a crash
Commit and Rollback: The commit operation saves all changes made in the
transaction as permanent. The rollback operation reverts the changes made in the
transaction
Two-Phase Commit Protocol: In distributed systems, this protocol ensures that a
transaction is committed in all participating nodes, or none at all, to maintain
consistency
Concurrency control
Manages simultaneous access to data in a multi-user environment
© 2025 Save My Exams, Ltd. Get more and ace your exams at [Link] 34
Techniques:
Locking: prevents multiple transactions from accessing the same data Your notes
simultaneously
Timestamping: assigns a unique timestamp to each transaction
Transaction management
Use database management systems (DBMS) with built-in transaction support
Implement custom transaction logic using SQL or other query languages
Test and monitor transactions to ensure ACID compliance and performance
Worked Example
© 2025 Save My Exams, Ltd. Get more and ace your exams at [Link] 35
RestaurantReview is a website that allows users to leave reviews and ratings for
different restaurants
Your notes
The website uses a database with the following structure
Record Locking
Record locking is a technique used in database management systems (DBMS) to
prevent conflicting access to data by multiple transactions or processes
It ensures data consistency and integrity when multiple users or processes try to read,
modify, or delete records simultaneously
Key Concepts
Lock: A mechanism that prevents access to a database record by other
transactions while a specific transaction is using the record
Lock granularity: Refers to the size of the locked data, ranging from a single row to
an entire table
Types of Locks
Shared lock (Read lock): Allows multiple transactions to read a record
simultaneously, but prevents modifications or deletions until the lock is released
Exclusive lock (Write lock): Allows only one transaction to access and modify a
record, blocking other transactions from reading or writing to the locked record
until the lock is released
Benefits of Record Locking
Maintains data consistency and integrity by preventing conflicting modifications
© 2025 Save My Exams, Ltd. Get more and ace your exams at [Link] 36
Allows concurrent read access to records without compromising data consistency
Improves database performance by enabling multiple users to access data Your notes
simultaneously, while managing access to prevent conflicts
Redundancy
Redundancy can occur when the same piece of data is stored in more than one table in a
database. This can either be by accident or by design
It can lead to inconsistencies in the data and/or wasted storage space
© 2025 Save My Exams, Ltd. Get more and ace your exams at [Link] 37