Cambridge AS Level Computer Science 9618 · 8.3 Data Definition Language (DDL) and Data Manipulation Language (DML)

Q24 · 9618/13/O/N/24 Q4

Worked solution from the Databases Paper 1 Theory Fundamentals booklet, Part 2 of 2.

Q249618/13/O/N/24original Q4Structured · 19 marks
Question 4 from 9618/13/O/N/24

Worked solution

(a)

A foreign key is a field that is the primary key of another table. Look at SALE(SaleID, BatchID, CustomerID, Quantity, Date).

Foreign key 1: BatchID, table BATCH [1]

Foreign key 2: CustomerID, table CUSTOMER [1]

(b)

SELECT SUM(Quantity)
FROM SALE
WHERE CustomerID = "0034E"
AND Date >= #01/01/2023#
AND Date <= #31/12/2023#;

SELECT SUM(Quantity) [1]

FROM SALE WHERE with one correct condition [1]

AND with the remaining correct conditions (all of the year 2023) [1]

(c)(i)

CREATE TABLE BATCH(
    BatchID VARCHAR(6) NOT NULL,
    Type VARCHAR(20) NOT NULL,
    Flavour VARCHAR(20) NOT NULL,
    Size FLOAT,
    SellingPrice CURRENCY,
    EndDate DATE,
    PRIMARY KEY (BatchID)
);

CREATE TABLE BATCH with brackets, all statements inside them [1]

BatchID, Type and Flavour as VARCHAR (text) [1]

... with suitable constraints, for example NOT NULL [1]

Size as a decimal, SellingPrice as currency and EndDate as a date [1]

PRIMARY KEY set as BatchID [1]

(c)(ii)

Type, Flavour, Size and SellingPrice repeat for the same kind of ice cream (for example Plain Vanilla 1 at 2.20 appears twice), so move them to their own table.

BATCH(BatchID, IceCreamID, EndDate)
ICE_CREAM(IceCreamID, Type, Flavour, Size, SellingPrice)

A new table with a suitable name, such as ICE_CREAM [1]

... containing Type, Flavour, Size and SellingPrice [1]

... with a suitable primary key (IceCreamID) [1]

A foreign key IceCreamID in BATCH that links to the primary key of ICE_CREAM [1]

(d)

Entity: a real-life object (thing) that is stored as a table in the database [1]

Attribute: an item of data about an entity (a field) [1]

(e)

Write three points about how the DBMS keeps the data correct:

The DBMS enforces referential integrity [1]

... for example cascade update / delete, so if data changes in one place it is updated everywhere else [1]

... and makes sure each foreign key has a matching primary key [1]

KEY IDEANormalising means moving repeated groups of data into their own table and linking them back with a foreign key.
TOTAL 19 marks

Official mark scheme

Mark scheme for 9618/13/O/N/24 question 4
VIDEO
▶ Starts at Q4 (33:00)

Starts at Q4 (33:00) · by Zafar Ali Khan (ZAK). Tap the picture to open it on YouTube.

Solutions follow the official Cambridge mark schemes; marks are shown in grey. Videos are from other YouTube channels. Paper codes read component / series / year: M/J = May/June, O/N = October/November. Past-paper questions © UCLES, reproduced for classroom practice.