Cambridge 9618 A Level Computer
Science - Topic 8: Databases
1. Introduction to Databases
A database is an organized collection of data that can be easily accessed, managed, and
updated.
Traditional file-based systems have several limitations such as data redundancy,
inconsistency, and poor data sharing capabilities.
Databases provide a systematic and efficient way of storing, retrieving, and managing
data.
2. Relational Database Concepts
Relational databases organize data into tables (relations), where each table consists of
rows (tuples) and columns (attributes).
Key terminologies:
- Entity: A real-world object or concept.
- Attribute: A characteristic or property of an entity.
- Tuple: A single record or row in a table.
- Primary Key: A unique identifier for each record in a table.
- Foreign Key: An attribute in one table that links to the primary key in another table to
establish a relationship.
- Candidate Key: An attribute, or set of attributes, that can uniquely identify a tuple.
- Secondary Key: An attribute used for accessing records, not necessarily unique.
3. Entity-Relationship (ER) Modelling
ER Diagrams are used to visually represent the structure of a database.
Components include entities, relationships, and attributes.
Cardinality defines the numerical relationship between instances of one entity and
instances of another (e.g., one-to-one, one-to-many, many-to-many).
4. Normalisation
Normalization is the process of organizing data to reduce redundancy and improve data
integrity.
First Normal Form (1NF): Ensures atomicity – no repeating groups or arrays.
Second Normal Form (2NF): Removes partial dependencies – all non-key attributes are
fully dependent on the primary key.
Third Normal Form (3NF): Removes transitive dependencies – non-key attributes are
dependent only on the primary key.
Benefits: Reduces redundancy, improves data integrity, easier maintenance.
5. Database Management System (DBMS)
A DBMS is software that interacts with users, applications, and the database itself to
capture and analyze data.
Functions include:
- Data storage, retrieval, and update
- Security management (user permissions, access rights)
- Concurrency control and transaction management
- Backup and recovery
- Data dictionary maintenance
6. Structured Query Language (SQL)
SQL is the standard language for querying and manipulating databases.
Data Definition Language (DDL):
- CREATE TABLE, ALTER TABLE, DROP TABLE – define and modify database
structures.
Data Manipulation Language (DML):
- SELECT, INSERT, UPDATE, DELETE – manage data within tables.
Advanced queries include:
- WHERE, ORDER BY, GROUP BY, HAVING, JOIN operations (INNER, LEFT, RIGHT,
FULL).
Aggregate functions: COUNT, SUM, AVG, MIN, MAX.
Joins:
- INNER JOIN: Returns records with matching values.
- LEFT/RIGHT JOIN: Returns all records from one table, and matched records from the
other.
- FULL OUTER JOIN: Returns all records when there is a match in either table.
7. Transactions and ACID Properties
A transaction is a sequence of operations performed as a single logical unit of work.
ACID properties:
- Atomicity: All operations complete successfully or none.
- Consistency: The database remains in a valid state before and after the transaction.
- Isolation: Transactions do not interfere with each other.
- Durability: Once committed, changes are permanent, even in case of system failure.
8. Security and Access Control
Database security ensures that only authorized users have access to the database and its
resources.
Access rights can be defined using GRANT and REVOKE statements in SQL.
Common threats: SQL injection, unauthorized access, data breaches.
Countermeasures: input validation, use of parameterized queries, role-based access
control.
9. Backup and Recovery
Regular backups protect data against loss or corruption.
Types of backups:
- Full backup: complete copy of the database.
- Incremental backup: copies changes since the last backup.
- Differential backup: copies changes since the last full backup.
Recovery mechanisms ensure data can be restored after failure.