Skip to topic
    ← Back to course topics

    Databases and SQL — CCEA A-Level Computer Science

    Databases and SQL explained

    This subtopic focuses on the foundational principles of relational databases, including the precise definition of tables (relations), tuples (rows), and attributes (columns), along with the critical roles of primary and foreign keys in maintaining data integrity and establishing relationships. It further covers the systematic process of normalization up to third normal form (3NF), a technique essential for eliminating data redundancy and update anomalies through the analysis of functional dependencies. Mastery of these concepts is vital for designing efficient, scalable database systems in real-world applications such as inventory management, customer records, and transactional systems.

    Your focus

    1. Define tables, tuples, attributes, primary keys, foreign keys
    2. Normalise data to 3NF

    Databases and SQL exam tips

    Topic Overview

    Databases and SQL form the backbone of modern data management, enabling efficient storage, retrieval, and manipulation of structured data. In the CCEA A-Level Computer Science specification, this topic covers relational database theory, normalisation, and the practical use of Structured Query Language (SQL). You will learn how to design tables with appropriate primary and foreign keys to maintain data integrity, and how to write SQL queries to extract meaningful information. Understanding databases is crucial for any software developer, data analyst, or systems architect, as nearly every application relies on a database backend.

    This topic builds on earlier concepts of data representation and file handling, but introduces a formal approach to data organisation. You will explore the principles of normalisation up to Third Normal Form (3NF) to eliminate redundancy and avoid update anomalies. SQL is the standard language for interacting with relational databases, and you will master commands such as SELECT, INSERT, UPDATE, DELETE, JOIN, and subqueries. The ability to design a normalised database and query it efficiently is a key skill assessed in both written exams and practical programming tasks.

    Mastering databases and SQL not only prepares you for the CCEA A-Level exam but also equips you with industry-relevant skills. In the wider subject of Computer Science, databases intersect with topics like data structures, algorithms, and system design. A solid grasp of this area will help you understand how large-scale systems manage data, from social media platforms to banking systems. By the end of this topic, you should be able to design a database from a given scenario, normalise it to 3NF, and write complex SQL queries to answer business questions.

    Key Concepts
    • →Relational database structure: tables, rows (records), columns (fields), primary keys, foreign keys, and relationships (one-to-one, one-to-many, many-to-many).
    • →Normalisation: the process of organising data to reduce redundancy and dependency, typically up to Third Normal Form (1NF, 2NF, 3NF).
    • →SQL commands: DDL (CREATE, ALTER, DROP) and DML (SELECT, INSERT, UPDATE, DELETE), including JOINs (INNER, LEFT, RIGHT) and subqueries.
    • →Data integrity: entity integrity (primary key uniqueness), referential integrity (foreign key constraints), and domain integrity (data types and constraints).
    • →Transaction management: ACID properties (Atomicity, Consistency, Isolation, Durability) and the use of COMMIT and ROLLBACK.
    Marking Points
    • Award credit for accurately defining a table as a relation composed of tuples and attributes, with clear distinction between the structural and data components.
    • Demonstrate understanding of primary keys as unique identifiers for tuples and foreign keys as attributes that establish links between tables, enforced by referential integrity.
    • Show ability to identify and eliminate data redundancy by normalizing to 3NF, including explicit explanation of how 1NF, 2NF, and 3NF conditions are met and any anomalies resolved.
    Examiner Tips
    • 💡When defining keys, always specify the scope: a primary key uniquely identifies tuples within a table, while a foreign key references a primary key in a related table; use clear examples.
    • 💡For normalization questions, systematically decompose: first list all functional dependencies, then transform to 1NF by ensuring atomic values, then remove partial dependencies for 2NF, and finally eliminate transitive dependencies for 3NF, annotating each step.
    • 💡To maximize marks, explicitly state how each normal form condition is satisfied and which anomalies (insertion, deletion, update) are prevented, linking theory to practical database design scenarios.
    • 💡When writing SQL queries, always specify the columns you need instead of using SELECT * — this shows precision and can improve performance. Examiners look for efficient queries.
    • 💡For normalisation questions, work step by step: identify the primary key, check for partial dependencies (2NF), then transitive dependencies (3NF). Show your working clearly to gain method marks.
    • 💡Practice writing JOINs with aliases (e.g., FROM Students s JOIN Enrolments e ON s.studentID = e.studentID). This makes queries more readable and is a sign of good style.
    Common Mistakes
    • Confusing primary key and foreign key roles, e.g., assuming a foreign key must be unique or that a primary key can be null.
    • Incorrectly applying normalization rules, such as failing to remove partial dependencies in 2NF or leaving transitive dependencies in 3NF, often due to misidentifying functional dependencies.
    • Misconceiving that normalization is about splitting tables arbitrarily rather than methodically addressing specific dependency problems.
    • Misconception: A primary key can be NULL. Correction: A primary key must be unique and NOT NULL; it uniquely identifies each record.
    • Misconception: Normalisation always improves performance. Correction: While normalisation reduces redundancy, it can increase the number of JOINs, which may slow down queries. Denormalisation is sometimes used for performance reasons.
    • Misconception: SQL is case-insensitive for everything. Correction: SQL keywords are case-insensitive, but string comparisons are case-sensitive in many databases (e.g., 'Smith' != 'smith' unless using a case-insensitive collation).
    Frequently Asked Questions
    What is the difference between a primary key and a foreign key?
    A primary key is a unique identifier for each record in a table; it must contain unique values and cannot be NULL. A foreign key is a field in one table that refers to the primary key of another table, establishing a relationship between the two tables. Foreign keys enforce referential integrity, ensuring that values in the foreign key column correspond to existing primary key values in the referenced table.
    How do I normalise a database to 3NF?
    First, ensure the table is in 1NF: each cell contains a single value, and each column has a unique name. Second, achieve 2NF by removing partial dependencies — every non-key column must depend on the whole primary key (not just part of it). Third, achieve 3NF by removing transitive dependencies — non-key columns should not depend on other non-key columns. Typically, you split tables and create relationships using foreign keys.
    What is the difference between INNER JOIN and LEFT JOIN?
    An INNER JOIN returns only rows where there is a match in both tables. A LEFT JOIN returns all rows from the left table, and matching rows from the right table; if there is no match, NULL values are returned for columns from the right table. Use INNER JOIN when you only need records that have related data, and LEFT JOIN when you need all records from the left table regardless of matches.
    How do I write a SQL query to find duplicate records?
    You can use the GROUP BY clause with HAVING to find duplicates. For example: SELECT column1, column2, COUNT(*) FROM table GROUP BY column1, column2 HAVING COUNT(*) > 1; This groups rows by the columns you want to check for duplicates and filters groups with more than one occurrence.
    What are ACID properties in databases?
    ACID stands for Atomicity, Consistency, Isolation, and Durability. Atomicity ensures that a transaction is all-or-nothing. Consistency ensures that a transaction brings the database from one valid state to another. Isolation ensures that concurrent transactions do not interfere with each other. Durability ensures that once a transaction is committed, it remains so even after a system failure.
    How do I use subqueries in SQL?
    A subquery is a query nested inside another query, often used in WHERE, FROM, or SELECT clauses. For example, to find students who scored above the average: SELECT * FROM Students WHERE score > (SELECT AVG(score) FROM Students); Subqueries can return single values, rows, or tables. They are useful for complex conditions but can sometimes be replaced by JOINs for better performance.