Computer Science · A3

Databases

Design, normalise and query relational databases with SQL. In 7Quest it is Deep Archive: 9 stages, 93 quick questions and 27 exam-style ones.

What the stages cover

Codes follow the 2027 guide (A1–A4 and B1–B4). HL-only stages are marked. Each stage is a short lesson, quick questions, a minigame and an exam-style question.

  1. Relational databases
    You will be able to describe tables, records, fields and keys, and evaluate the benefits and limitations of a relational database.
    Syllabus A3.1.1
  2. Schemas and ER diagrams
    You will be able to describe conceptual, logical and physical schemas, and construct an ERD showing cardinality and modality in crow’s foot notation.
    Syllabus A3.2.1, A3.2.2
  3. Data types and CREATE TABLE
    You will be able to choose the data type of each field, construct tables with PKs, FKs and constraints, and distinguish DDL from DML.
    Syllabus A3.2.3, A3.2.4, A3.3.1
  4. Normalisation to 3NF
    You will be able to identify anomalies, explain 1NF, 2NF and 3NF, normalise a table to 3NF and evaluate when to denormalise.
    Syllabus A3.2.5, A3.2.6, A3.2.7
  5. SQL queries and JOINs
    You will be able to construct SELECT queries with filters, patterns, sorting and two-table joins using INNER JOIN.
    Syllabus A3.3.2
  6. Changing data, grouping and aggregates
    You will be able to change data with INSERT, UPDATE and DELETE, explain what those changes cost when columns are indexed, and group rows with GROUP BY and HAVING. HL extension: calculating with SUM, AVG, MIN and MAX for reports.
    Syllabus A3.3.2, A3.3.3, A3.3.4
  7. Views and transactionsHL
    You will be able to compare virtual and materialised views, and describe how ACID transactions maintain integrity under concurrent access.
    Syllabus A3.3.5, A3.3.6
  8. Alternative and distributed databasesHL
    Outline the main non-relational database models and describe the features of distributed databases.
    Syllabus A3.4.1, A3.4.4
  9. Data warehouses, OLAP and data miningHL
    Explain what data warehouses are for and how OLAP and data mining turn stored data into business decisions.
    Syllabus A3.4.2, A3.4.3

Two questions to try

Written for 7Quest in the style of the exam, not taken from past papers. Answer first, then open the markscheme.

Construct4 marksChanging data, grouping and aggregates

Using Loan(LoanID, BookID, MemberID, LoanDate, Returned), construct an SQL query that shows each MemberID and the number of loans that member has not yet returned (Returned = 0), only for members with more than one such loan, from the most loans to the fewest.

Show the markscheme

Markscheme (4 marks)

  1. SELECT MemberID, COUNT(*) FROM Loan
  2. WHERE Returned = 0 (filters the rows before grouping).
  3. GROUP BY MemberID
  4. HAVING COUNT(*) > 1 and ORDER BY COUNT(*) DESC (condition on the count in HAVING, not in WHERE).

A full-marks answer

SELECT MemberID, COUNT(*) AS NotReturned
FROM Loan
WHERE Returned = 0
GROUP BY MemberID
HAVING COUNT(*) > 1
ORDER BY NotReturned DESC;
WHERE removes the returned loans before the groups are formed; GROUP BY makes one group per member; HAVING keeps only the groups whose count is greater than 1, which WHERE could not do because the counts do not exist until the rows are grouped. On the library data the result is member 3 with 2 loans.

Explain8 marksPaper 1 styleHLChallengeViews and transactions

A chain of libraries uses one database for all its branches. Front-desk volunteers need to see which books are on loan, and head office wants a dashboard of the number of loans at each branch, refreshed every night.

(a) Describe how a view could let the volunteers do their job without access to members’ personal details. [2]

(b) Explain whether a virtual view or a materialised view is more suitable for the head-office dashboard. [3]

(c) A member returns a book and immediately borrows another. Explain how a transaction keeps the two changes consistent if the system crashes between them. [3]

Show the markscheme

Markscheme (8 marks)

  1. (a) A view selects only the columns/rows the volunteers need (e.g. book title, member name, loan date), not addresses or phone numbers…
  2. (a) …and the volunteers are given permission on the view but not on the base tables.
  3. (b) Materialised: the result (loans per branch) is stored, so the dashboard reads it quickly instead of recalculating a large grouped query every time.
  4. (b) The data only needs to be as recent as the nightly refresh, so the staleness of a materialised view is acceptable.
  5. (b) A virtual view would always be up to date but would recalculate the aggregation over all loans on every access, which is slower / loads the live database.
  6. (c) Both changes (mark the return, insert the new loan) are placed in one transaction between BEGIN TRANSACTION and COMMIT.
  7. (c) Atomicity: if the system crashes before COMMIT, the DBMS rolls back the incomplete transaction, so neither change is kept (no half-finished state).
  8. (c) Durability: once COMMIT has completed, both changes are permanent even after a crash.

A full-marks answer

(a) The library creates a view that shows only what the front desk needs, such as the title of each book on loan, the member’s name and the loan date, without addresses or phone numbers. The volunteers are granted permission to query this view but not the Member table itself, so the personal details are hidden from them.

(b) A materialised view is more suitable. Counting the loans of every branch is a grouped query over a very large table; a materialised view stores its result, so the dashboard opens instantly instead of recalculating the counts each time and slowing down the live system. The data being up to a day old does not matter, because head office only needs figures as fresh as the nightly refresh; a virtual view would be always current, but at a cost the dashboard does not need.

(c) The return and the new loan are written in one transaction, started with BEGIN TRANSACTION and ended with COMMIT. Because of atomicity, if the system crashes after the return has been recorded but before COMMIT, the DBMS rolls the transaction back when it restarts, so the database is never left with only one of the two changes. Once COMMIT has completed, durability guarantees that both changes survive any later crash.

The other 25 questions in this topic are in the app, marked point by point, and anything you miss comes back in your review. If this is the topic you find hardest, you can make it your free topic and do all of it, with short practice tests on it, without paying or giving a card.

Start Computer Science free