Worked solution from the Databases Paper 1 Theory Fundamentals booklet, Part 2 of 2.
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]
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]
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]
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]
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]
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]
▶ 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.