EXAM QUESTIONS · AS LEVEL 9618
Databases Exam-Style Questions with Answers (A Level 9618)
Original exam-style questions on file-based limitations, relational database terms, keys and referential integrity, E-R relationships, normalisation to 3NF, DBMS features, and SQL DDL and DML including JOIN and GROUP BY for Cambridge AS & A Level Computer Science 9618 (Paper 1). There are 27 marks in total. Try each question on paper first, then press Show answer to see the mark scheme. Answers that can be calculated mark themselves.
Describe three limitations of a file-based approach to storing data compared with a relational database.
Show answer
Any three from:
- Data redundancy: the same data is stored in more than one file.
- Data inconsistency: copies of the same data can become different.
- Data dependency: programs are written for a particular file structure, so changing the structure means changing the programs.
- Difficult to search and combine data from different files.
- Poorer security / harder to control who can access which data.
Define each term.
- Candidate key [1]
- Foreign key [1]
- Referential integrity [1]
- Secondary key [1]
Show answer
- An attribute (or set of attributes) that could be chosen as the primary key because it uniquely identifies every tuple. [1]
- An attribute in one table that is the primary key of another table, used to link the tables. [1]
- Every foreign key value must match an existing primary key value in the linked table. [1]
- An attribute, not the primary key, that is indexed so records can be searched/sorted quickly. [1]
A table LOAN(LoanID, MemberID, MemberName, BookID, BookTitle) is in 1NF. Explain why it is not in 3NF and show how it should be normalised.
Show answer
- MemberName depends on MemberID, and BookTitle depends on BookID, not on the primary key LoanID – these are non-key (transitive) dependencies. [1]
- MEMBER(MemberID, MemberName) and BOOK(BookID, BookTitle) [1]
- LOAN(LoanID, MemberID, BookID), with MemberID and BookID as foreign keys. [1]
Describe three features of a DBMS that help to keep data secure and correct.
Show answer
Any three, with a description from:
- Data dictionary – stores metadata such as table names, data types, keys and validation rules.
- Access rights – different users can only read or change the data they are allowed to.
- User accounts and passwords.
- Validation rules – check data as it is entered.
- Automatic back-ups.
- Record locking – stops two users updating the same record at the same time.
Write an SQL script to create the table ORDERS shown below. OrderID is the primary key, and CustomerID is a foreign key that links to the CUSTOMER table.
Show answer
CREATE TABLE ORDERS ( OrderID INTEGER, CustomerID VARCHAR(5), Amount REAL, PRIMARY KEY (OrderID), FOREIGN KEY (CustomerID) REFERENCES CUSTOMER(CustomerID) );
- 1 mark: CREATE TABLE ORDERS ( … );
- 1 mark: all three fields with suitable data types
- 1 mark: PRIMARY KEY (OrderID)
- 1 mark: FOREIGN KEY (CustomerID) REFERENCES CUSTOMER(CustomerID)
Use these two tables for Questions 6–9. A shop stores its customers and their orders in a relational database.
CUSTOMER
| CustomerID | Name | Town |
|---|---|---|
| C1 | Aylin | Izmir |
| C2 | Ben | Leeds |
| C3 | Chen | Izmir |
| C4 | Dara | Cork |
ORDERS
| OrderID | CustomerID | Amount |
|---|---|---|
| 501 | C1 | 40 |
| 502 | C3 | 25 |
| 503 | C1 | 15 |
| 504 | C2 | 60 |
| 505 | C3 | 35 |
State the output of this query:
SELECT ORDERS.OrderID, CUSTOMER.Name FROM ORDERS INNER JOIN CUSTOMER ON ORDERS.CustomerID = CUSTOMER.CustomerID WHERE CUSTOMER.Town = 'Izmir' ORDER BY ORDERS.OrderID;
Show answer
| OrderID | Name |
|---|---|
| 501 | Aylin |
| 502 | Chen |
| 503 | Aylin |
| 505 | Chen |
1 mark for the four correct rows, 1 mark for the correct order. [2]
- Write an SQL query to output each CustomerID with the total amount of their orders. [2]
- State the total shown for C1. [1]
Show answer
SELECT CustomerID, SUM(Amount) FROM ORDERS GROUP BY CustomerID;
1 mark: SELECT CustomerID, SUM(Amount) FROM ORDERS, 1 mark: GROUP BY CustomerID [2]- 55 (40 + 15) [1]
Write SQL statements to:
- add a new order 506 for customer C4 with an amount of 20 [1]
- change the town of customer C2 to York [1]
- delete order 503. [1]
Show answer
INSERT INTO ORDERS (OrderID, CustomerID, Amount) VALUES (506, 'C4', 20); UPDATE CUSTOMER SET Town = 'York' WHERE CustomerID = 'C2'; DELETE FROM ORDERS WHERE OrderID = 503;
1 mark for each correct statement. [3]
Explain why the DBMS would reject an attempt to insert an order for customer C9.
Show answer
- C9 does not exist as a primary key in the CUSTOMER table. [1]
- Referential integrity is enforced, so a foreign key value must match an existing primary key value. [1]
Frequently asked questions
What is the difference between 2NF and 3NF?
A table in 2NF has no partial dependencies on part of a composite key. A table in 3NF is also free of non-key dependencies: no non-key attribute depends on another non-key attribute.
Are these past paper questions?
No. These are original exam-style questions written by a Computer Science teacher in the Cambridge style.
Revise the topic: 9618 databases notes · Normalisation 1NF, 2NF, 3NF guide · SQL practice playground · All exam-style questions