Question bank › IB Computer Science › Theme A – Concepts of computer science

A3 Databases

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]

2Core3 marks

Use the tables below.

Tutor
TutorIDTutorName
1Mr Khan
2Ms Reid
3Mr Cole
Student
StudentIDNameYearTutorID
1Aisha121
2Ben132
3Chloe121
4Dev133
5Elin122
6Femi121
Result
StudentIDSubjectScore
1CS78
1Maths65
2CS55
2Maths70
3CS90
3Maths82
4CS48
5CS66
5Maths71
6CS72

Write an SQL query to list the names of all Year 12 students in reverse alphabetical order. [3]

3HardHL only4 marks

The table below stores exam results.

Result
StudentIDSubjectScore
1CS78
1Maths65
2CS55
2Maths70
3CS90
3Maths82
4CS48
5CS66
5Maths71
6CS72

Write an SQL query that outputs the StudentID and average Score of every student who has at least two results and an average score above 70. [4]

4Hard5 marks

Use the tables below.

Student
StudentIDNameYearTutorID
1Aisha121
2Ben132
3Chloe121
4Dev133
5Elin122
6Femi121
Result
StudentIDSubjectScore
1CS78
1Maths65
2CS55
2Maths70
3CS90
3Maths82
4CS48
5CS66
5Maths71
6CS72

Construct an SQL query to output the Name and CS Score of every student in tutor group 1 (TutorID = 1) who scored at least 75 in CS. [5]

5Stretch6 marks

An unnormalized table stores orders:

ORDERS(OrderID, OrderDate, CustomerID, CustomerName, CustomerCity, {ProductID, ProductName, UnitPrice, Quantity})

The items in braces repeat for each product on the order. Construct a database in third normal form (3NF) from this table. In your answer, identify the problem removed at each stage (1NF, 2NF, 3NF) and give the final relations with primary keys marked (PK) and foreign keys marked (FK). [6]

6Standard5 marks

A hotel stores its bookings in the table below. BookingDate is stored as text in the form YYYY-MM-DD.

Booking
BookingIDRoomIDBookingDateGuests
100142027-03-022
100272027-03-051
100342027-03-092
1004122027-03-114
100572027-03-122

(a) Construct an SQL statement to add booking 1006 for room 12 on 2027-03-14 for 2 guests. [2]

(b) Booking 1003 now has 3 guests. Construct an SQL statement to make this change. [2]

(c) The BookingDate column is indexed. Outline why changing values in an indexed column has a performance cost. [1]

7Standard3 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]

Still losing marks on this topic?

Book a free introductory session and we'll find exactly which step is costing you.

Book a free intro