A video streaming service uses a relational database with two tables. FILM FilmID Title Director Genre Rating ReleaseYear F01 Space Voyager K. Adams Sci-Fi ...

Assessment: Computer Science 0478 | Paper 2 Mock 01 | Algorithms, Programming and Logic Subject: Computer Science - 0478

Question 1 Report

A video streaming service uses a relational database with two tables.

FILM

FilmIDTitleDirectorGenreRatingReleaseYear
F01Space VoyagerK. AdamsSci-FiPG2022
F02Silent EchoM. RiveraThriller152021
F03Ocean QuestK. AdamsAdventurePG2023
F04Night ShiftL. WongThriller182020
F05Golden DaysM. RiveraDrama122023

VIEWING

ViewIDUserIDFilmIDViewDateRating
V01U100F012024-04-014
V02U200F032024-04-025
V03U100F022024-04-033
V04U300F012024-04-035
V05U200F052024-04-054

Note: the Rating field in VIEWING stores user ratings (1 to 5 stars), which is different from the age Rating in FILM.

(a) Identify the primary key and foreign key in the VIEWING table. [2]

(b) Write an SQL query to find all films directed by 'K. Adams' released after 2021. [2]

Answer Details

(a) In the VIEWING table: [2]

  • Primary key: ViewID [1]. It uniquely identifies each viewing record. No two rows share the same ViewID.
  • Foreign key: FilmID [1]. It references the FilmID primary key in the FILM table, linking each viewing record to the film that was watched.

Note that UserID could also be considered a foreign key if a USER table existed, but based on the tables shown, only FilmID links to another table in the schema.

(b) Finding all films directed by K. Adams released after 2021: [2]

SELECT *
FROM FILM
WHERE Director = 'K. Adams' AND ReleaseYear > 2021

[1] for WHERE Director = 'K. Adams', [1] for AND ReleaseYear > 2021.

Both conditions must be true simultaneously, so AND is the correct operator. The expected result:

FilmIDTitleDirectorGenreRatingReleaseYear
F01Space VoyagerK. AdamsSci-FiPG2022
F03Ocean QuestK. AdamsAdventurePG2023

F01 (2022) and F03 (2023) are both directed by K. Adams and released after 2021. Note the question says "after 2021" (strictly greater than), so a film from 2021 would not be included.

Download The App On Google Playstore

Everything you need to excel in your exams

Green Bridge CBT Mobile App
Personalized AI Learning Chat Assistant
200,000+ Exam Questions Across IGCSE, JAMB, WAEC & NECO
Over 3,900 Lesson Notes
Offline Support - Learn Anytime, Anywhere
Green Bridge Timetable
Literature Summaries & Potential Questions
Track Your Performance & Progress
In-depth Explanations for Comprehensive Learning