Question bank › IB Computer Science › A3 Databases

Relational database fundamentals, schemas, ERDs and keys

Answer on paper first, then reveal the mark scheme one mark at a time.

1Core3 marks

Define the terms primary key and foreign key, and outline one reason for using a foreign key in a relational database. [3]

2Standard3 marks

Students can join many clubs and each club has many students. Explain how this many-to-many relationship is implemented in a relational database. [3]

3Core6 marks

A gym stores details of its members in a table MEMBER. Some example values are shown.

FieldExample value
PhoneNumber07700 900123
JoinDate15 January 2026
MonthlyFee24.99
IsStudentYes / No

(a) State the most appropriate data type for each of the four fields. [4]

(b) The database designer stores PhoneNumber as an INTEGER. Outline one effect of this choice. [1]

(c) A second designer stores JoinDate as text in the form dd/mm/yyyy. Outline one effect of this choice when members are listed in order of joining. [1]

Stuck on Relational database fundamentals, schemas, ERDs and keys?

Get it sorted in a free 30-minute session

We work through your weakest questions on this topic on Zoom. I reply the same day.

4Core4 marks

A school is designing a database for its library. Three design documents have been written.

Document P: Members borrow books. A book can be borrowed many times, but only by one member at a time. Each loan has a due date.

Document Q: BOOK(ISBN, Title, Author, YearPublished); MEMBER(MemberID, Name, TutorGroup); LOAN(LoanID, ISBN, MemberID, DateOut, DateDue). ISBN is a 13-character string; YearPublished is an integer.

Document R: The tables are stored in the file library.db on the school's server SSD. An index on Title is held as a B-tree, and the LOAN table is backed up nightly.

(a) State which level of database schema (conceptual, logical or physical) each document describes. [3]

(b) Outline one benefit of keeping the logical schema separate from the physical schema. [1]

5Standard6 marks

The entity-relationship diagram (ERD), drawn in crow's foot notation, shows part of the design of a database for a veterinary surgery.

(a) State the cardinality of the relationship between OWNER and PET. [1]

(b) With reference to the symbols at both ends of the relationship between PET and APPOINTMENT, explain the modality of this relationship. [2]

(c) Identify the table(s) that will contain a foreign key, naming the primary key each foreign key refers to. [2]

(d) Explain why the foreign key for the OWNER–PET relationship is placed in the PET table rather than in the OWNER table. [1]

OWNERPETAPPOINTMENTVET ownshascarries out
6Standard6 marks

A swimming club records race results in a table RESULT. A swimmer may race in several events, and in each event may swim in a heat and, if fast enough, a final. Details of swimmers are held in a table SWIMMER and details of events in a table EVENT.

SwimmerIDEventCodeRoundLaneTimeSec
S014FR50Heat328.41
S014FR50Final427.95
S022FR50Heat529.10
S022BK100Heat571.36
S031FR50Heat428.02
S031FR50Final428.20
S014BK100Heat369.84
S040FR50Heat330.55

(a) With reference to the data, explain why SwimmerID cannot be the primary key of RESULT. [1]

(b) A student suggests the composite key (SwimmerID, EventCode). Using the data, explain why this is not suitable. [1]

(c) Identify a composite key for RESULT that does not include Lane or TimeSec. [1]

(d) Identify two foreign keys in RESULT, stating the table each one links to. [2]

(e) Explain why TimeSec should not form part of the primary key. [1]

7Standard6 marks

An online shop keeps all its data in a single flat-file table ORDERS. Every one of its 1200 order records stores the customer's name (30 bytes) and full address (60 bytes) as well as the order details. The orders were placed by 150 different customers. Part of the file is shown; all three orders were placed by the same customer.

OrderNoCustNameCustAddressItem
5011R. Mensah12 Mill Lane, LeedsDesk lamp
5034R. Mensah12 Mill Ln, LeedsBulbs x4
5102R. Mensah3 Park Road, YorkShelf

The shop plans to move to a relational database with a CUSTOMER table and an ORDER table. Each customer will be given a 4-byte CustomerID, which is also stored in each order record as a foreign key.

(a) Calculate the number of bytes saved by this change, considering only the customer name, address and CustomerID data. Show your working. [3]

(b) Identify the data integrity problem shown in the extract. [1]

(c) Explain how the relational design prevents this problem. [2]

8Hard6 marks

A start-up is building a social media app. Posts can contain text, images, polls or video, and new post types are added every few months. Comments can be replied to, giving threads nested to any depth. The developers write the app in an object-oriented language, with a Post class whose objects hold lists of Comment objects. The company expects billions of posts within a few years. User accounts and paid subscriptions must also be stored.

Discuss whether a relational database is a suitable choice for storing this app's data. [6]

9Stretch8 marks

A driving school is designing a relational database.

  • Each instructor has a unique staff number, a name and a phone number. A newly hired instructor may not yet have any learners.
  • Each learner has a learner ID, a name and a date of birth, and is assigned to exactly one instructor.
  • A learner books lessons. Each lesson has a date and a start time, is for one learner, and takes place in one car. A learner who has just registered may not yet have booked a lesson.
  • Each car has a registration number and a model. A car can be used for many lessons; a new car may not yet have been used.

(a) Construct an entity-relationship diagram (ERD) for this database, showing the cardinality and modality of each relationship. [4]

(b) Construct the table designs, in the form TABLE(Field1, Field2, …), clearly identifying every primary key and foreign key. [4]

10Hard6 marks

A company database contains two tables. DeptCode in EMPLOYEE is a foreign key referring to DEPARTMENT. Referential integrity is enforced and no cascading rules are set.

DEPARTMENT

DeptCodeDeptName
FINFinance
HRHuman Resources
LEGLegal
OPSOperations

EMPLOYEE

EmpIDNameDeptCode
101Ama OwusuFIN
102Ben ClarkeOPS
103Chen WeiHR
104Dina PatelOPS

(a) For each operation, state whether the database management system will accept or reject it, giving a reason. [4]

  1. Add employee 105, Eli Brook, in department MKT.
  2. Delete the department FIN.
  3. Add employee 103, Fay Lund, in department HR.
  4. Delete the department LEG.

(b) Two HR clerks open employee 102's record at the same time. One changes the department to HR; the other changes the name and saves a moment later. Explain how concurrency control prevents one change from being lost. [2]

Stuck on this topic?

Book a free 30-minute session on WhatsApp and we'll find exactly which step is costing you the marks. Or build a timed paper on it.

Free 30-minute session