Revision Library

Databases and SQL - Worksheets, Questions and Revision

14 original exam-style questions - 6 pages of questions with a full mark scheme - free printable PDF.

Download PDFJump to mark scheme (page 7)Read the revision guide
« Previous: Advanced Algorithms: Searching, Sorting and Path-FindingNext: Networking and the Internet »
Revision Library
revisionlibrary.co.uk
A-Level · AQA

A2.7 Databases and SQL

AQA 7517 · Calculators not allowed · about 130 minutes
Total Marks
Name: _______________________________    Date: ____ / ____ / ______
Answer ALL questions. Show all your working.

Elm Grove Music Academy: a database case study

Original scenario written for Revision Library.

Elm Grove Music Academy offers one-to-one instrumental lessons and is building a relational database to replace its old spreadsheet system. Questions 1 to 5 take the academy's original, unnormalised booking data and normalise it step by step to Third Normal Form (3NF), and model it with an entity relationship (ER) diagram. Questions 6 to 11 use the resulting normalised database (with sample data added) to write and interpret SQL statements. Questions 12 to 14 look at how the database is used and maintained once it is in service: transaction processing, concurrent access, and the trade-off between normalisation and denormalisation.

1
Before building its database, Elm Grove Music Academy's systems analyst reviews some key relational database terms.
(a)Define the term 'primary key'.(2)
(b)Define the term 'foreign key'.(2)
(c)Define the term 'candidate key'.(2)
(d)Using an example from Elm Grove Music Academy's booking data, explain what is meant by a 'composite key'.(2)
(Total for Question 1 is 8 marks)
2
Elm Grove Music Academy's original spreadsheet stores each student's lesson bookings as a repeating group, as shown below (Figure 1). Assume the business rule: a student may book lessons for several different instruments, but can only have one active booking per instrument (so a student cannot have two separate bookings for, say, Piano at the same time).

Figure 1 (unnormalised, UNF):
StudentIDStudentNameStudentPhoneLessons (InstrumentID, InstrumentName, InstructorID, InstructorName, Day, Time, Duration, Cost)
S01Priya Chatterjee07911 123456(I01, Piano, T01, Daniel Osei, Monday, 16:00, 30, 18.00), (I02, Guitar, T02, Fiona Clarke, Wednesday, 17:00, 45, 24.00)
S02Callum Reid07922 654321(I01, Piano, T01, Daniel Osei, Tuesday, 15:30, 30, 18.00)

(Duration is in minutes; Cost is in GBP pounds sterling.)
(a)State one problem that would occur if this unnormalised (UNF) data was stored and processed in this form.(2)
(b)Convert the data in Figure 1 into First Normal Form (1NF) by removing the repeating group. Write out the resulting flat table, including every attribute, and state a suitable primary key.(4)
(Total for Question 2 is 6 marks)
3
Question 2(b)'s 1NF relation is:

Booking1NF(StudentID, StudentName, StudentPhone, InstrumentID, InstrumentName, InstructorID, InstructorName, Day, Time, Duration, Cost)

with primary key (StudentID, InstrumentID).
(a)Explain why (StudentID, InstrumentID) is a suitable primary key for this relation, rather than StudentID alone or InstrumentID alone.(2)
(b)Identify TWO partial dependencies in this 1NF relation. For each, state the determinant and the dependent attribute(s).(4)
(c)Hence convert the relation into Second Normal Form (2NF). Write out each resulting relation, underlining the primary key of each.(4)
(Total for Question 3 is 10 marks)
4
The 2NF Booking relation from Question 3(c) is:

Booking(StudentID, InstrumentID, InstructorID, InstructorName, Day, Time, Duration, Cost), primary key (StudentID, InstrumentID).
(a)State what is meant by a transitive dependency between non-key attributes.(2)
(b)Identify the transitive dependency present in the 2NF Booking relation above.(2)
(c)Convert the relations into Third Normal Form (3NF). Write out the complete, final set of relations for Elm Grove Music Academy's database, underlining each primary key and labelling each foreign key (FK).(6)
(Total for Question 4 is 10 marks)
5
Using the final 3NF relations from Question 4(c), an entity relationship (ER) diagram is to be produced for Elm Grove Music Academy's database.
(a)Identify the four entities required, and state which one is needed only to resolve a many-to-many relationship (a 'link' or associative entity).(2)
(b)Draw an entity relationship diagram for this database. Show each entity, its primary key (underlined) and any foreign keys, and label the cardinality of every relationship.(6)
(c)Explain why a link entity (BOOKING) is needed to model the relationship between STUDENT and INSTRUMENT, rather than connecting them with a single direct relationship.(2)
(Total for Question 5 is 10 marks)
6
Figure 2: Elm Grove Music Academy's database (following normalisation in Questions 2 to 4), with sample data added. Questions 6 to 11 all refer to this database.

Student table:
StudentIDStudentNameStudentPhone
S01Priya Chatterjee07911 123456
S02Callum Reid07922 654321
S03Aisha Bello07933 789012
S04Jack Whitfield07944 345678
S05Freya Thomson07955 901234
S06Zainab Hussain07966 567890

Instrument table:
InstrumentIDInstrumentName
I01Piano
I02Guitar
I03Violin
I04Drums

Instructor table:
InstructorIDInstructorName
T01Daniel Osei
T02Fiona Clarke
T03Marcus Lindqvist

Booking table (primary key: StudentID + InstrumentID):
StudentIDInstrumentIDInstructorIDDayTimeDurationCost
S01I01T01Monday16:003018.00
S01I02T02Wednesday17:004524.00
S02I01T01Tuesday15:303018.00
S03I03T03Monday18:004522.50
S03I02T02Thursday10:003021.00
S04I01T01Monday09:006032.00
S04I04T02Friday16:303020.00
S05I02T02Wednesday09:303021.00

(Duration is in minutes; Cost is in GBP pounds sterling.)
(a)Write an SQL query to display the StudentID, InstrumentID and Time of every booking that takes place on a Monday, ordered by Time, earliest first.(4)
(b)State the StudentID, InstrumentID and Time values that this query would return, in the order they would appear.(2)
(Total for Question 6 is 6 marks)
7
Questions 6 to 11 refer to Figure 2 (Question 6).
(a)Explain why an INNER JOIN between the Booking and Student tables is needed to display a student's name alongside their booking details, following the normalisation carried out in Questions 3 and 4.(2)
(b)Write an SQL query, using an INNER JOIN, to display the StudentName and Cost for every booking taught by instructor T01 (Daniel Osei).(4)
(c)State the result this query would return.(2)
(Total for Question 7 is 8 marks)
8
Figure 2 (Question 6) is used again for this question.
(a)Write an SQL query to display, for each instructor, their InstructorName and the total number of bookings they teach. Only include instructors who teach more than one booking, and order the output with the highest number of bookings first.(6)
(b)State the final output of this query.(2)
(Total for Question 8 is 8 marks)
9
Elm Grove Music Academy needs to make the following changes to its database. Assume each part below is applied independently to the original data in Figure 2 (Question 6).
(a)A new student, Harriet Osborne, joins the academy. Her StudentID is S07 and her phone number is 07977 112233. Write an SQL statement to add her record to the Student table.(2)
(b)Callum Reid (S02) changes his phone number to 07900 445566. Write an SQL statement to update his record.(2)
(c)Freya Thomson (S05) cancels her Wednesday Guitar lesson with instructor T02. Write an SQL statement to delete only this booking record (do not delete her Student record).(2)
(Total for Question 9 is 6 marks)
10
Using the original Student and Booking data in Figure 2 (Question 6) - that is, not including any of the changes made in Question 9.
(a)Write an SQL query, using a subquery, to display the StudentID and StudentName of every student who has not booked any lessons.(4)
(b)State the result this query would return.(1)
(Total for Question 10 is 5 marks)
11
Figure 2 (Question 6) is used again for this question.
(a)A database administrator attempts to run the statement: DELETE FROM Student WHERE StudentID = 'S01'; Explain why the DBMS might reject this statement.(3)
(b)Describe how the database could instead be configured to automatically remove Priya Chatterjee's booking records at the same time as her student record, and give one risk of using this approach.(3)
(Total for Question 11 is 6 marks)
12
A separate part of Elm Grove Music Academy's system processes online payments. When a parent pays a GBP 50 deposit, the system must (1) subtract GBP 50 from the parent's stored account balance and (2) add GBP 50 to the academy's income record, using two SQL UPDATE statements grouped together.
(a)Define the term 'transaction' in the context of a database system.(2)
(b)State what is meant by COMMIT and ROLLBACK.(2)
(c)Discuss how each of the four ACID properties (Atomicity, Consistency, Isolation, Durability) contributes to the reliable processing of the deposit payment described above, particularly if the system were to fail partway through.(6)
(Total for Question 12 is 10 marks)
13
Elm Grove Music Academy's booking system is used by several members of staff at once.
(a)Explain what is meant by record locking in a multi-user database system.(2)
(b)Two members of staff both try to change the Time of the same booking record (S04, I04) at the same moment. Explain, using pessimistic record locking, how the DBMS would prevent this causing a lost update.(3)
(Total for Question 13 is 5 marks)
14
Elm Grove Music Academy's manager suggests that, to make monthly reports run faster, the database should be deliberately denormalised, for example by storing StudentName directly in the Booking table again (as it was before Question 3), instead of looking it up via a join each time. Discuss the advantages and disadvantages of denormalising the database in this way, compared with keeping it fully normalised to 3NF.
(Total for Question 14 is 6 marks)
Mark scheme · A2.7 Databases and SQL

Question 1

Question 2

Question 3

Question 4

Question 5

Question 6

Question 7

Question 8

Question 9

Question 10

Question 11

Question 12

Question 13

Question 14

Mark your answers

This checks your answers in your browser, stores nothing on a server and needs no account.

Question 1

8 marks
Did your answer earn the marks?

Question 2

6 marks
Did your answer earn the marks?

Question 3

10 marks
Did your answer earn the marks?

Question 4

10 marks
Did your answer earn the marks?

Question 5

10 marks
Did your answer earn the marks?

Question 6

6 marks
Did your answer earn the marks?

Question 7

8 marks
Did your answer earn the marks?

Question 8

8 marks
Did your answer earn the marks?

Question 9

6 marks
Did your answer earn the marks?

Question 10

5 marks
Did your answer earn the marks?

Question 11

6 marks
Did your answer earn the marks?

Question 12

10 marks
Did your answer earn the marks?

Question 13

5 marks
Did your answer earn the marks?

Question 14

6 marks
Did your answer earn the marks?
Mark my answers