Implementation (SQA National 5 Computing Science): Exam Questions

Exam code: X816 75

55 mins13 questions
1a
3 marks

A database is used to store data about restaurants. This includes the type of food they serve, the average price of a meal and a rating of 1, 2, 3, 4 or 5 stars.

The SQL query below is executed.

SELECT name, address, phoneNumber
FROM restaurant
WHERE (foodType = "Italian" OR foodType = "French")
AND starRating > 1
AND starRating < 5
ORDER BY averagePrice ASC

Describe the output that would be listed under the headings name, address and phoneNumber when the above query is executed.

1b
1 mark

State which SQL operation would be required to change the phone number of a restaurant in the database.

2a
4 marks

A car retailer has four showrooms.

A relational database is used to store details of the four showrooms and the cars they have for sale.

Showroom

showroomID

city

manager

Gla1

Glasgow

Ray Rain

Gla2

Glasgow

Kate Jones

Abd

Aberdeen

Sue Gearan

Dun

Dundee

Sadiq Yavuz

Car

carID

make

model

colour

seats

salePrice

showroomID

1

McLaren

F1

blue

3

900000

Dun

2

Jaguar

XKR

silver

2

70000

Gla1

3

SMART

Sports

green

3

22300

Abd

4

Nissan

GT-R

red

4

80000

Dun

5

Alfa Romeo

Giulia

green

2

50000

Dun

6

Audi

TT Coupe

white

4

12050

Gla2

7

Mazda

MX-5

black

2

21987

Abd

8

Jaguar

F-Type

red

2

105200

Dun

9

SMART

Sports

yellow

3

17000

Gla1

An SQL statement is implemented to find all two seater cars and produces the output below.

make

model

salePrice

Alfa Romeo

Giulia

50000

Alfa Romeo

GTV

35000

Alfa Romeo

Spider

66000

Fiat

Spider 124

26345

Jaguar

F-Type

105200

Jaguar

XJS

45595

Jaguar

XKR

70000

Lotus

Evora

72500

Mazda

MX-5

21987

Porsche

Cayman 718

40000

Write the SQL statement that will produce this output, in the order shown.

2b
2 marks

One functional requirement is to output the make, model and price of cars costing less than 60000 which are not in Glasgow.

SELECT make, model, colour, salePrice
FROM Car
WHERE showroomID = "Abd"
AND salePrice < 60000;

Give two reasons why the SQL statement would not produce the required output.

3
2 marks

A model collector keeps information about the items collected in a database. A query has been run and the output is shown below.

modelNumber

title

theme

pieceAmount

cost

1279

Space Base

Space

1422

125

7525

Colour Fun

Classic

1685

90

1457

Lady Liberty

Architect

1500

90

5271

Command Rover

Space

750

70

1280

Dino Compound

Adventure

612

60

6598

Creative Box

Classic

790

45

8182

Astronaut

Space

647

45

3688

Century Hawk

Star Battles

253

30

1094

Tomb Treasure

Adventure

161

20

2281

River Raft

Adventure

18

6

Complete the SQL statement used to produce this sorted output.

SELECT modelNumber, title, theme, pieceAmount, cost

FROM Model

ORDER BY......................................................................................................

4
4 marks

A band booking company has a range of bands that can be booked for various events. It wants a database to store information on bands and their bookings.

A band can play more than one event. An event can only have one band.

When a band is being booked for an event the form below is completed.

Event booking form with fields for event name, date, venue, email and a dropdown for band selection. Submit button is at the bottom.

When the band has been booked, the following e-mail is sent to the organiser

Congratulations.

You are all booked. You have been given the exclusive event ID 1318.

Ross Wonder is looking forward to playing at your event.

The database has been created. Sample data from each table is shown below.

Band

bandRef

bandName

cost

numMembers

genre

RW172

Ross Wonder

1500

2

Rock

ML435

Of Men and Lions

1250

5

Country

BP908

Brightplay

2200

6

Rock

LP241

Les Pencils

1800

2

Pop

BB456

The Bright Brothers

1300

3

Electronic

ME243

Miceica

2000

4

Country

SI746

20 Seconds to Irvine

1100

5

Folk

Event

eventID

eventName

date

bandRef

venue

bookingEmail

1215

Paterson Wedding

10/04/2026

ML435

Lakeside Lodge

[email protected] (opens in a new tab)

1318

Charity Ball

25/09/2025

RW172

The Old Poet

[email protected] (opens in a new tab)

1154

Oscar’s Luau

11/08/2025

ME243

The Old Poet

[email protected] (opens in a new tab)

1089

Award Ceremony

05/12/2025

SI746

Driftwater

[email protected] (opens in a new tab)

1706

Hogmanay Dance Off

31/12/2025

BB456

The Unicorn

[email protected] (opens in a new tab)

2011

Afternoon Tea

26/03/2026

BP908

The Old Poet

[email protected] (opens in a new tab)

Complete the SQL statement below that will display the name of any country band playing at ‘The Old Poet’ and the date of the event.

SELECT ...............................................................................................

FROM..................................................................................................

WHERE................................................................................................

5a
2 marks

Caledonian Wheels organises a motorsport racing championship. A database is used to store data on racing teams and their individual drivers. The data stored in the database is shown below.

Team

teamID

teamName

titlesWon

location

RR32

Rapid Racers

7

Italy

SS21

Swift Streaks

3

United Kingdom

TT16

Turbo Titans

2

Germany

VR12

Velocity Vipers

4

Italy

ER54

Elite Racers

1

United Kingdom

PV81

Prime Speed

5

Spain

Driver

driverNum

forename

surname

wins

points

teamID

1

Shannon

Kelly

5

125

ER54

3

Ezri

Wuzik

2

50

PV81

4

Jackie

Price

2

50

RR32

11

Kai

West

4

100

SS21

14

Charlie

Wilkinson

1

25

TT16

18

Moss

Gray

0

0

VR12

22

Kris

Hunt

1

25

SS21

31

Meenal

Ibrahim

3

75

VR12

55

Ollie

Graham

6

150

TT16

63

Gerry

Fox

0

0

PV81

77

Jackie

West

1

25

ER54

81

Akari

Ogawa

0

0

RR32

The following SQL statement is implemented in the database.

SELECT teamID, teamName, titlesWon
FROM Team
WHERE (teamID = "PV81" OR location = "Italy") AND titlesWon >=5

Write the expected output from this SQL statement.

5b
4 marks

Jackie West won her 2nd race of the season increasing her points to 50.

Write the SQL statement to update Jackie’s details.

5c
1 mark

A new driver is to be added.

INSERT INTO Driver (driverNum, forename, surname, wins,
points, teamID)
VALUES (99, "Thomas", "Webb", 0, 0, "PC81")

When this SQL statement is run, an error message is displayed stating that the record cannot be added.

Explain why an error message is displayed.

6a
2 marks

Teams take part in a technology competition. Their details are stored in a table called Team. The sorted output below was produced by executing a query.

teamID

schoolID

teamName

noOfMembers

technology

T1

936

Pseudo Boom

3

Robot

T22

871

Brainy Bunch

4

E-Glasses

T56

658

Thinking Caps

2

Air drone

T24

658

B.H.B

2

VR headset

T67

402

Fuzz Logic

4

Health tracker

T29

214

Alpha 1.0

5

Artificial intelligence

T37

214

Successors

3

Land drone

T46

214

Brainy Bunch

4

VR headset

T99

197

Elec-tricks

2

Smart watch

Complete the SQL statement used to produce this sorted output.

SELECT teamID, schoolID, teamName, noOfMembers, technology

FROM Team

ORDER BY...................................................

6b
2 marks

Brainy Bunch from schoolID 214 has been disqualified from the competition.

Write the SQL statement to remove them from the table.

7a
1 mark

The Games Lab is a video game testing company that programmers can send games to for testing. Each game is allocated to a tester who works on several different games. Testers are based in three offices — Scotland, France and Australia — and only accept games rated 12A, 15 and 18.

The Game table is implemented. Some of the data it currently stores is shown below.

Game

gameID

gameName

programmer

rating

testerID

multiplatform

378B

World Away

CodeQueen

12A

EX2706

Yes

311H

Denta Deet

AbdurPSK

15

EX777

No

484D

Cupland

LindyLoo

12A

EX360

No

257P

Heat Wave

EMC2

15

EX277

Yes

183B

Water Rage

CodeQueen

15

EX987

Yes

021B

Bee-Hive

AcroGymGal

12A

EX120

Yes

782C

Combat45

AbdurPSK

12A

EX2706

No

The game ‘Water Rage’ has been reclassified as an 18 rating. The following SQL statement was implemented to make this change.

UPDATE Game
SET rating = "18"
WHERE programmer = "CodeQueen"

Explain why the SQL statement above would give an unexpected result.

7b
1 mark

Rewrite the SQL statement to give the expected result.

8a
6 marks

A database stores data on a local netball league. The Club table stores data of the clubs that play in the league. The Player table stores data on each player.

Sample data from each table is shown below.

Club

clubID

clubName

trainingVenue

contactNo

division

A2706

Joint Forces

Glasgow

01415829631

3

B1803

Shooting Stars

Renfrewshire

01245668123

2

E0408

Team Titans

Glasgow

01415571239

1

P2507

Hot Shots

Lanarkshire

01245789456

1

H0311

Throwing Tigers

Glasgow

01418529637

2

Player

playerID

name

email

age

position

clubID

358

Meenal

[email protected] (opens in a new tab)

21

Goal keeper

E0408

562

Jacob

[email protected] (opens in a new tab)

25

Goal shooter

A2706

981

Tara

[email protected] (opens in a new tab)

24

Centre

P2507

742

Ibrahim

[email protected] (opens in a new tab)

36

Wing defence

E0408

801

Devin

[email protected] (opens in a new tab)

30

Goal shooter

B1803

129

Amber

[email protected] (opens in a new tab)

21

Wing attack

A2706

232

Xander

[email protected] (opens in a new tab)

38

Goal defence

E0408

475

Harris

[email protected] (opens in a new tab)

36

Goal attack

E0408

603

Zohra

zohra_lan@g_

(i) The netball league wants a list of players who meet at least one of the following criteria:

  • train in Lanarkshire

  • play for a team in division 2.

Complete the SQL query below.

[4]

SELECT clubName, name, playerID
FROM...........................
WHERE..........................

(ii) Describe how this SQL query should be tested.

[2]

8b
1 mark

Explain why it is better to have referential integrity implemented before adding a new player to the netball database.

9
2 marks

The sorted output below was produced by running a query in a database.

contractCode

contractLength

phoneType

storage

IP24128

24 months

iPhone14

128 GB

IP18128

18 months

iPhone14

128 GB

GA18128

18 months

Galaxy S22

128 GB

GA24256

24 months

Galaxy Z

256 GB

PI18256

18 months

Pixel 6a

256 GB

IP18256

18 months

iPhone 14

256 GB

XP12256

12 months

Xperia 5

256 GB

IP24512

24 months

iPhone 14

512 GB

GA24512

18 months

Galaxy Z

512 GB

Complete the SQL statement used to produce this sorted output.

SELECT contractCode, contractLength, phoneType, storage
FROM contract
ORDER BY...............................................
10a
6 marks

A window cleaning company wishes to create a database to store information about staff and the houses they clean. The company provides examples of information they would like to include.

Two notebook pages showing house and staff details. House: ID DAL7233, Jacob Brown, 8 Wishaw Place, 8 windows. Staff: ID 6290, Noah Canavan, 25 hours weekly.

The relational database is implemented. Sample data from both tables is shown below.

House

houseID

customerName

address

directDebit

windows

cost

staffID

BON4523

Claire Banks

168 Ferry Place

Yes

6

13

1613

DAL8001

Stephen Jones

7F Millbank

No

3

7

1752

EDI3189

Ian Collins

15 Robin Ave

Yes

8

12

1613

Staff

staffID

staffName

contactTel

hoursPerWeek

2160

Daniel Buchan

07721454187

35

1613

Jessie Tait

07378565190

15

1752

Nick Haig

07745176623

27.5

1617

Dagmara Dyner

07178251143

35

The database is used to identify all customer names and addresses that have 5 or more windows and are allocated to staff member Fatima Khan.

Complete the SQL statement below that would produce this output.

SELECT ..................................................................................................

FROM .....................................................................................................

WHERE...................................................................................................

[5]

(ii)

The owner at 15 Robin Avenue has moved house. The new owner’s name is Sue Horaz. They will still pay via direct debit.

Complete the SQL statement below to update this record.

UPDATE House

SET...........................................................................................
WHERE houseID = "EDI3189" ;

[1]

10b
1 mark

The following details are to be added into the House table.

houseID

customerName

address

directDebit

windows

cost

staffID

BON9070

Tia Neil

77B Park Close

No

5

9

3630

When attempting to add this data, the following error message is displayed.

Error message window with text: "Error - referential integrity! The relationship does not allow this record to be inserted."

Explain the reason for this.

11
2 marks

Bright Stars organise and run classes for children. Classes are organised into blocks, each running for 8 weeks.

The table Class stores data about the classes available.

The table Booking stores data about the children and their parents/guardians.

Sample data from each table is shown below.

Class

classID

leaderName

day

time

location

sessionBlock

classAge

S1-141

Suzanne

Mon

10:45

Grange

Summer

1-2 Years

S2-228

Claire

Tue

11:50

Lothianburn

Autumn

3-4 Years

S2-871

Jo

Mon

13:00

Gorebridge

Spring

3-4 Years

B1-121

David

Thur

15:30

Biggar

Winter

Babies

S1-333

Alexander

Wed

13:00

Coldingham

Summer

1-2 Years

S2-519

Claire

Fri

10:45

Lothianburn

Autumn

3-4 Years

B3-435

Jose

Wed

09:30

Gorebridge

Spring

Babies

Booking

bookingID

parentName

email

childName

childDOB

paid

classID

EF220731

Esme Faulds

[email protected] (opens in a new tab)

Quinn

25/09/2022

No

S1-333

TR238270

Tim Roberts

[email protected] (opens in a new tab)

Lucas

05/02/2023

Yes

B1-121

ZA200836

Zoe Archer

[email protected] (opens in a new tab)

Blake

11/01/2020

Yes

S2-288

FY229853

Fen Yang

[email protected] (opens in a new tab)

Freya

06/06/2022

No

S1-333

A new class is going to be added for Autumn which will be run by Adam. This is added by executing the following SQL statement.

INSERT INTO Class (classID, leaderName, day, time,
location, sessionBlock, classAge)
VALUES ("B1-497", "Adam", "Mon", 15:30, "Grange","Autumn",
"Babies");

Tim Roberts, who made booking TR238270, would like to book their child Lucas onto this new class. He has not yet paid for the class.

Write an SQL statement that will add this booking to the Booking table, using the bookingID TR653726.

12
3 marks

A database table stores the following data.

Result

forename

surname

test1

test2

Julie

White

7

92

Aaima

Waheed

34

67

Chun

Yang

27

52

Olivia

Arran

58

98

Mia

Branan

78

90

Claire

McKay

10

7

Scott

Harper

42

47

The following SQL statement is implemented in the database.

SELECT forename, surname
FROM Result
WHERE test1 < 10 OR test2 > 90;

Write the expected output from the SQL statement.

13a
3 marks

A property renovation company requires a relational database to store information about the tasks to be carried out on each room of a house.

The functional requirements for the database are identified:

  • Store details of each room in the house.

  • Store details of each task.

  • Output a list of tasks carried out by one of the following trades people: electrician, builder, plasterer, decorator, carpenter, plumber.

  • Output a list of tasks completed for a single room.

The relational database is implemented. The data it currently stores is shown below.

Room

name

width

length

height

floor

living

4.20

4.05

2.20

ground

kitchen

3.25

2.70

2.20

ground

dining

3.05

3.10

2.20

ground

bedroom

3.70

4.15

2.15

first

bathroom

1.80

2.10

2.15

first

Task

taskID

description

dateStarted

hours

Taken completed

trades Person

cost(£)

name

1

Fit new sink

12/4/2022

4

true

plumber

98.58

bathroom

2

Paint living room door

12/4/2022

false

decorator

living

3

Paint kitchen

13/4/2022

3

true

decorator

120.00

kitchen

4

Fit kitchen cupboards

15/4/2022

32

true

carpenter

1790.00

kitchen

5

Plaster walls

16/4/2022

false

plasterer

bedroom

6

Fit new bath

16/4/2022

8

true

plumber

278.54

bathroom

7

Fit new door to bedroom

18/4/2022

false

carpenter

bedroom

8

Paint bedroom

18/4/2022

false

decorator

bedroom

A porch is to be built onto the front of the house.

The porch is added as a new room by executing the following SQL statement.

INSERT INTO Room (name,width,length,height,floor)
VALUES ("Porch",1.20,1.40,2.10,"ground");

The task ‘construct porch’ needs to be added. This task was started by a builder on 19 April 2022. The work is not completed so the hours taken and cost are not yet known.

Write an SQL statement that will add this work to the Task table.

13b
2 marks

The bedroom is no longer being renovated.

The following SQL statements are written to remove the bedroom tasks from the Task table.

DELETE FROM Task
WHERE taskID = 5;
DELETE FROM Task
WHERE taskID = 7;
DELETE FROM Task
WHERE taskID = 8;

Write a single efficient SQL statement to remove the bedroom tasks.