O Level Computer Science (2210)
Databases Banker
8 questions · about 5% of the marks we indexed · examined in 8 of 8 sessions.
Practice questions
Original questions written by HomiLabs in the style of the exam, with answers and mark schemes. They are not
Cambridge past paper questions and have not been reviewed by Cambridge. Try each one before opening the answer.
Q1Queries (SQL, query-by-example in 2022) · Core · Paper 2 style · 3 marksTable BOOKS:BookID | Title | Author | Genre | Year | Copies | OnLoanB101 | River of Stars | S. Malik | Fiction | 2015 | 3 | TRUEB102 | Atoms Explained | R. Khan | Science | 2019 | 2 | FALSEB103 | The Silk Route | A. Haider | History | 2008 | 4 | TRUEB104 | Desert Moon | S. Malik | Fiction | 2021 | 1 | FALSEB105 | Coding for All | L. Chen | Science | 2022 | 5 | TRUEB106 | Indus Valley Life | A. Haider | History | 2012 | 2 | FALSEB107 | Night Train | M. Okafor | Fiction | 2018 | 2 | TRUEB108 | Planets Today | R. Khan | Science | 2016 | 3 | FALSE
- (a) Write the output of this query:SELECT Title, AuthorFROM BOOKSWHERE Genre = 'Science'; [3]
Show answer
- (a) Atoms Explained | R. KhanCoding for All | L. ChenPlanets Today | R. Khan
1 mark for each correct row (Title and Author only, in table order); no extra fields or rows.
Q2Queries (SQL, query-by-example in 2022) · Core · Paper 2 style · 4 marksTable BOOKS:BookID | Title | Author | Genre | Year | Copies | OnLoanB101 | River of Stars | S. Malik | Fiction | 2015 | 3 | TRUEB102 | Atoms Explained | R. Khan | Science | 2019 | 2 | FALSEB103 | The Silk Route | A. Haider | History | 2008 | 4 | TRUEB104 | Desert Moon | S. Malik | Fiction | 2021 | 1 | FALSEB105 | Coding for All | L. Chen | Science | 2022 | 5 | TRUEB106 | Indus Valley Life | A. Haider | History | 2012 | 2 | FALSEB107 | Night Train | M. Okafor | Fiction | 2018 | 2 | TRUEB108 | Planets Today | R. Khan | Science | 2016 | 3 | FALSE
- (a) State the output of:SELECT COUNT(*)FROM BOOKSWHERE OnLoan = TRUE; [1]
- (b) Write an SQL query to output the BookID and Title of every book written by A. Haider. [3]
Show answer
- (a) 4
B1 – four books have OnLoan TRUE (B101, B103, B105, B107).
- (b) SELECT BookID, TitleFROM BOOKSWHERE Author = 'A. Haider';
1 mark: SELECT BookID, Title. 1 mark: FROM BOOKS. 1 mark: WHERE Author = 'A. Haider'.
Q3Queries (SQL, query-by-example in 2022) · Core · Paper 2 style · 6 marksTable PATIENTS:PatientID | Name | Age | City | BloodGroup | InsuredP001 | Hina | 34 | Lahore | O+ | TRUEP002 | Kamran | 61 | Karachi | A+ | FALSEP003 | Sana | 8 | Lahore | B+ | TRUEP004 | Imran | 45 | Multan | O+ | TRUEP005 | Zara | 27 | Karachi | AB- | FALSEP006 | Tariq | 72 | Lahore | A+ | TRUEP007 | Nida | 15 | Multan | O- | FALSE
- (a) Write the output of:SELECT Name, AgeFROM PATIENTSWHERE City = 'Lahore'; [3]
- (b) Complete the query to show the PatientID and Name of every patient who is not insured.SELECT ……………… , ………………FROM ………………WHERE ……………… = ………………; [3]
Show answer
- (a) Hina | 34Sana | 8Tariq | 72
1 mark per correct row, Name and Age only.
- (b) SELECT PatientID, NameFROM PATIENTSWHERE Insured = FALSE;
1 mark: PatientID, Name. 1 mark: PATIENTS. 1 mark: Insured = FALSE.
Q4Queries (SQL, query-by-example in 2022) · Core · Paper 2 style · 4 marksTable PRODUCTS:Code | Item | Category | Price | StockS01 | Rice 5 kg | Grocery | 1450.00 | 30S02 | Green tea | Drinks | 380.50 | 0S03 | Cooking oil | Grocery | 2100.00 | 12S04 | Mango juice | Drinks | 220.00 | 45S05 | Soap bar | Household | 95.00 | 80S06 | Lentils 1 kg | Grocery | 420.00 | 0S07 | Washing powder | Household | 650.00 | 18S08 | Mineral water | Drinks | 70.00 | 120
- (a) Write a query that outputs the Item and Price of every product in the Drinks category. [3]
- (b) State how many rows your query outputs. [1]
Show answer
- (a) SELECT Item, PriceFROM PRODUCTSWHERE Category = 'Drinks';
1 mark each line.
- (b) 3
Green tea, Mango juice, Mineral water.
Q5Queries (SQL, query-by-example in 2022) · Core · Paper 2 style · 5 marksTable MOVIES:MovieID | Title | Genre | Minutes | Rating | ReleasedM01 | Sky Riders | Action | 128 | 7.4 | 2021M02 | Quiet Lake | Drama | 104 | 8.1 | 2019M03 | Laugh Out | Comedy | 92 | 6.5 | 2022M04 | Iron Coast | Action | 141 | 6.9 | 2018M05 | Paper Hearts | Drama | 117 | 7.8 | 2023M06 | Zoo Day | Comedy | 85 | 7.1 | 2020
- (a) Write the output of:SELECT TitleFROM MOVIESWHERE Rating > 7.5; [2]
- (b) Write a query that outputs the Title and Minutes of all Comedy films. [3]
Show answer
- (a) Quiet LakePaper Hearts
1 mark each row; Title only.
- (b) SELECT Title, MinutesFROM MOVIESWHERE Genre = 'Comedy';
1 mark each line.
Q6Queries (SQL, query-by-example in 2022) · Core · Paper 2 style · 4 marksTable FLIGHTS:FlightNo | Destination | DepTime | Seats | PricePK301 | Dubai | 06:15 | 12 | 48000PK785 | London | 09:40 | 3 | 210000EK612 | Dubai | 13:05 | 40 | 52000QR605 | Doha | 15:30 | 0 | 61000PK213 | Jeddah | 18:45 | 25 | 95000TK715 | Istanbul | 22:10 | 7 | 120000
- (a) State the output of:SELECT COUNT(*)FROM FLIGHTSWHERE Destination = 'Dubai' OR Destination = 'Doha'; [1]
- (b) State the output of:SELECT SUM(Seats)FROM FLIGHTSWHERE Price > 100000; [1]
- (c) Explain the difference between COUNT and SUM in an SQL query. [2]
Show answer
- (a) 3
PK301, EK612, QR605.
- (b) 10
3 + 7.
- (c) COUNT gives the number of records that meet the condition; SUM adds up the values in a numeric field for those records.
1 mark each.
Q7Queries (SQL, query-by-example in 2022) · Standard · Paper 2 style · 7 marksTable BOOKS:BookID | Title | Author | Genre | Year | Copies | OnLoanB101 | River of Stars | S. Malik | Fiction | 2015 | 3 | TRUEB102 | Atoms Explained | R. Khan | Science | 2019 | 2 | FALSEB103 | The Silk Route | A. Haider | History | 2008 | 4 | TRUEB104 | Desert Moon | S. Malik | Fiction | 2021 | 1 | FALSEB105 | Coding for All | L. Chen | Science | 2022 | 5 | TRUEB106 | Indus Valley Life | A. Haider | History | 2012 | 2 | FALSEB107 | Night Train | M. Okafor | Fiction | 2018 | 2 | TRUEB108 | Planets Today | R. Khan | Science | 2016 | 3 | FALSE
- (a) Write the output of:SELECT Title, YearFROM BOOKSWHERE Genre = 'Fiction' AND Copies >= 2ORDER BY Year DESC; [3]
- (b) Write a query that outputs the total number of copies of all History books. [3]
- (c) State the output of your query in (b). [1]
Show answer
- (a) Night Train | 2018River of Stars | 2015
1 mark: correct two rows only (Desert Moon excluded as it has 1 copy). 1 mark: only Title and Year shown. 1 mark: in descending order of year.
- (b) SELECT SUM(Copies)FROM BOOKSWHERE Genre = 'History';
1 mark: SELECT SUM(Copies). 1 mark: FROM BOOKS. 1 mark: WHERE Genre = 'History'.
- (c) 6
4 + 2.
Q8Queries (SQL, query-by-example in 2022) · Standard · Paper 2 style · 7 marksTable PATIENTS:PatientID | Name | Age | City | BloodGroup | InsuredP001 | Hina | 34 | Lahore | O+ | TRUEP002 | Kamran | 61 | Karachi | A+ | FALSEP003 | Sana | 8 | Lahore | B+ | TRUEP004 | Imran | 45 | Multan | O+ | TRUEP005 | Zara | 27 | Karachi | AB- | FALSEP006 | Tariq | 72 | Lahore | A+ | TRUEP007 | Nida | 15 | Multan | O- | FALSE
- (a) A clinic wants to list children under 18 and adults over 60 for a vaccination drive. Write the output of:SELECT Name, CityFROM PATIENTSWHERE Age < 18 OR Age > 60ORDER BY Name; [4]
- (b) Write a query that outputs how many patients have blood group O+. [3]
Show answer
- (a) Kamran | KarachiNida | MultanSana | LahoreTariq | Lahore
1 mark: all four correct patients and no others. 1 mark: Name and City only. 2 marks: alphabetical order by Name (1 mark if one pair out of order).
- (b) SELECT COUNT(*)FROM PATIENTSWHERE BloodGroup = 'O+';
1 mark each line.
Q9Queries (SQL, query-by-example in 2022) · Standard · Paper 2 style · 8 marksTable FLIGHTS:FlightNo | Destination | DepTime | Seats | PricePK301 | Dubai | 06:15 | 12 | 48000PK785 | London | 09:40 | 3 | 210000EK612 | Dubai | 13:05 | 40 | 52000QR605 | Doha | 15:30 | 0 | 61000PK213 | Jeddah | 18:45 | 25 | 95000TK715 | Istanbul | 22:10 | 7 | 120000Price is in rupees; Seats is the number of seats still available.
- (a) Write the output of:SELECT FlightNo, Destination, PriceFROM FLIGHTSWHERE Seats > 0 AND Price < 100000ORDER BY Price; [4]
- (b) Write a query to output the FlightNo and DepTime of all flights to Dubai, earliest first. [4]
Show answer
- (a) PK301 | Dubai | 48000EK612 | Dubai | 52000PK213 | Jeddah | 95000
1 mark: correct three flights (QR605 excluded – no seats; others too expensive). 1 mark: correct fields. 2 marks: ascending order of price.
- (b) SELECT FlightNo, DepTimeFROM FLIGHTSWHERE Destination = 'Dubai'ORDER BY DepTime;
1 mark each line (ORDER BY DepTime ascending; ASC optional).
Q10Queries (SQL, query-by-example in 2022) · Standard · Paper 2 style · 7 marksTable PRODUCTS:Code | Item | Category | Price | StockS01 | Rice 5 kg | Grocery | 1450.00 | 30S02 | Green tea | Drinks | 380.50 | 0S03 | Cooking oil | Grocery | 2100.00 | 12S04 | Mango juice | Drinks | 220.00 | 45S05 | Soap bar | Household | 95.00 | 80S06 | Lentils 1 kg | Grocery | 420.00 | 0S07 | Washing powder | Household | 650.00 | 18S08 | Mineral water | Drinks | 70.00 | 120
- (a) The manager wants a list of items that need reordering because they are out of stock. Write a query that outputs the Code and Item of these products in alphabetical order of Item. [4]
- (b) Write the output of your query. [2]
- (c) State the output of:SELECT SUM(Stock)FROM PRODUCTSWHERE Category = 'Household'; [1]
Show answer
- (a) SELECT Code, ItemFROM PRODUCTSWHERE Stock = 0ORDER BY Item;
1 mark each line.
- (b) S02 | Green teaS06 | Lentils 1 kg
1 mark each row in correct order.
- (c) 98
80 + 18.
Q11Queries (SQL, query-by-example in 2022) · Standard · Paper 2 style · 7 marksTable WEATHER:StationID | City | Country | Rainfall | MaxTempW1 | Karachi | Pakistan | 2.5 | 36.4W2 | Murree | Pakistan | 41.0 | 22.1W3 | Mumbai | India | 88.2 | 31.0W4 | Colombo | Sri Lanka | 64.7 | 30.2W5 | Quetta | Pakistan | 0.0 | 33.8W6 | Dhaka | Bangladesh | 57.3 | 32.6W7 | Lahore | Pakistan | 18.9 | 38.0Rainfall is in mm for one week; MaxTemp is in °C.
- (a) Write the output of:SELECT City, RainfallFROM WEATHERWHERE Country = 'Pakistan' AND Rainfall > 10ORDER BY Rainfall DESC; [3]
- (b) Write a query that outputs the total rainfall recorded at the stations in Pakistan. [3]
- (c) State the output of your query in (b). [1]
Show answer
- (a) Murree | 41.0Lahore | 18.9
1 mark: correct rows only; 1 mark: fields; 1 mark: order.
- (b) SELECT SUM(Rainfall)FROM WEATHERWHERE Country = 'Pakistan';
1 mark each line.
- (c) 62.4
2.5 + 41.0 + 0.0 + 18.9.
Q12Queries (SQL, query-by-example in 2022) · Standard · Paper 2 style · 6 marksTable PATIENTS:PatientID | Name | Age | City | BloodGroup | InsuredP001 | Hina | 34 | Lahore | O+ | TRUEP002 | Kamran | 61 | Karachi | A+ | FALSEP003 | Sana | 8 | Lahore | B+ | TRUEP004 | Imran | 45 | Multan | O+ | TRUEP005 | Zara | 27 | Karachi | AB- | FALSEP006 | Tariq | 72 | Lahore | A+ | TRUEP007 | Nida | 15 | Multan | O- | FALSE
- (a) Write the output of:SELECT PatientID, NameFROM PATIENTSWHERE Age > 30 AND (City = 'Lahore' OR City = 'Multan')ORDER BY Name; [3]
- (b) Write a query that outputs the Name and Age of every patient in Karachi who is not insured, oldest first. [3]
Show answer
- (a) P001 | HinaP004 | ImranP006 | Tariq
1 mark: correct three patients only (over 30 and in Lahore or Multan; Kamran excluded as he is in Karachi). 1 mark: only PatientID and Name shown. 1 mark: ascending order of Name.
- (b) SELECT Name, AgeFROM PATIENTSWHERE City = 'Karachi' AND Insured = FALSEORDER BY Age DESC;
1 mark: SELECT Name, Age FROM PATIENTS. 1 mark: WHERE City = 'Karachi' AND Insured = FALSE. 1 mark: ORDER BY Age DESC. (Output would be Kamran 61, Zara 27.)
Q13Queries (SQL, query-by-example in 2022) · Challenge · Paper 2 style · 7 marksTable FLIGHTS:FlightNo | Destination | DepTime | Seats | PricePK301 | Dubai | 06:15 | 12 | 48000PK785 | London | 09:40 | 3 | 210000EK612 | Dubai | 13:05 | 40 | 52000QR605 | Doha | 15:30 | 0 | 61000PK213 | Jeddah | 18:45 | 25 | 95000TK715 | Istanbul | 22:10 | 7 | 120000
- (a) A travel agent wants the flight numbers and prices of all flights with fewer than 10 seats left, most expensive first. She writes:SELECT FlightNo, PriceFROM FLIGHTWHERE Seats > 10ORDER BY Price;Identify the three errors and write the corrected query. [4]
- (b) Write the output of the corrected query. [3]
Show answer
- (a) Errors: table name should be FLIGHTS; condition should be Seats < 10; ORDER BY Price should be DESC.Corrected:SELECT FlightNo, PriceFROM FLIGHTSWHERE Seats < 10ORDER BY Price DESC;
1 mark for each error identified and corrected (FLIGHTS; Seats < 10; DESC); 1 mark for the complete correct query.
- (b) PK785 | 210000TK715 | 120000QR605 | 61000
1 mark: correct three flights; 1 mark: fields; 1 mark: descending order.
Q14Queries (SQL, query-by-example in 2022) · Challenge · Paper 2 style · 7 marksTable PRODUCTS:Code | Item | Category | Price | StockS01 | Rice 5 kg | Grocery | 1450.00 | 30S02 | Green tea | Drinks | 380.50 | 0S03 | Cooking oil | Grocery | 2100.00 | 12S04 | Mango juice | Drinks | 220.00 | 45S05 | Soap bar | Household | 95.00 | 80S06 | Lentils 1 kg | Grocery | 420.00 | 0S07 | Washing powder | Household | 650.00 | 18S08 | Mineral water | Drinks | 70.00 | 120
- (a) Write the output of:SELECT Item, Category, PriceFROM PRODUCTSWHERE Price >= 200 AND Price <= 1500 AND Category <> 'Drinks'ORDER BY Price DESC; [4]
- (b) Write a query that outputs the number of products in the Grocery category that are in stock. [3]
Show answer
- (a) Rice 5 kg | Grocery | 1450.00Washing powder | Household | 650.00Lentils 1 kg | Grocery | 420.00
1 mark: correct rows only (Mango juice and Green tea excluded as Drinks; Cooking oil excluded on price). 1 mark: correct fields. 2 marks: descending price order.
- (b) SELECT COUNT(*)FROM PRODUCTSWHERE Category = 'Grocery' AND Stock > 0;
1 mark: COUNT. 1 mark: FROM PRODUCTS. 1 mark: both conditions joined with AND.
Q15Queries (SQL, query-by-example in 2022) · Challenge · Paper 2 style · 7 marksTable WEATHER:StationID | City | Country | Rainfall | MaxTempW1 | Karachi | Pakistan | 2.5 | 36.4W2 | Murree | Pakistan | 41.0 | 22.1W3 | Mumbai | India | 88.2 | 31.0W4 | Colombo | Sri Lanka | 64.7 | 30.2W5 | Quetta | Pakistan | 0.0 | 33.8W6 | Dhaka | Bangladesh | 57.3 | 32.6W7 | Lahore | Pakistan | 18.9 | 38.0
- (a) A heatwave warning is needed for every station with a maximum temperature above 32 °C or with no rainfall at all. Write a query that outputs the StationID and City of these stations in alphabetical order of City. [4]
- (b) Write the output of your query. [3]
Show answer
- (a) SELECT StationID, CityFROM WEATHERWHERE MaxTemp > 32 OR Rainfall = 0ORDER BY City;
1 mark: SELECT fields; 1 mark: FROM; 1 mark: both conditions joined with OR; 1 mark: ORDER BY City.
- (b) W6 | DhakaW1 | KarachiW7 | LahoreW5 | Quetta
1 mark: correct four stations; 1 mark: correct fields; 1 mark: alphabetical order.
Q16Queries (SQL, query-by-example in 2022) · Challenge · Paper 2 style · 8 marksTable MOVIES:MovieID | Title | Genre | Minutes | Rating | ReleasedM01 | Sky Riders | Action | 128 | 7.4 | 2021M02 | Quiet Lake | Drama | 104 | 8.1 | 2019M03 | Laugh Out | Comedy | 92 | 6.5 | 2022M04 | Iron Coast | Action | 141 | 6.9 | 2018M05 | Paper Hearts | Drama | 117 | 7.8 | 2023M06 | Zoo Day | Comedy | 85 | 7.1 | 2020
- (a) A streaming service wants films released in 2020 or later that last less than 2 hours, best rated first. Write the query. [4]
- (b) Write the output of your query (Title and Rating). [3]
- (c) State the output of:SELECT SUM(Minutes)FROM MOVIESWHERE Genre = 'Action'; [1]
Show answer
- (a) SELECT Title, RatingFROM MOVIESWHERE Released >= 2020 AND Minutes < 120ORDER BY Rating DESC;
1 mark: SELECT suitable fields (Title, plus Rating if shown); 1 mark: FROM MOVIES; 1 mark: both conditions with AND (120 minutes); 1 mark: ORDER BY Rating DESC.
- (b) Paper Hearts | 7.8Zoo Day | 7.1Laugh Out | 6.5
1 mark: correct three films; 1 mark: fields; 1 mark: order.
- (c) 269
128 + 141.
Q17Tables, fields, records, primary keys and data types · Core · Paper 2 style · 4 marksTable BOOKS:BookID | Title | Author | Genre | Year | Copies | OnLoanB101 | River of Stars | S. Malik | Fiction | 2015 | 3 | TRUEB102 | Atoms Explained | R. Khan | Science | 2019 | 2 | FALSEB103 | The Silk Route | A. Haider | History | 2008 | 4 | TRUEB104 | Desert Moon | S. Malik | Fiction | 2021 | 1 | FALSEB105 | Coding for All | L. Chen | Science | 2022 | 5 | TRUEB106 | Indus Valley Life | A. Haider | History | 2012 | 2 | FALSEB107 | Night Train | M. Okafor | Fiction | 2018 | 2 | TRUEB108 | Planets Today | R. Khan | Science | 2016 | 3 | FALSE
- (a) State the number of fields and the number of records in the table BOOKS. [2]
- (b) State the most suitable field for the primary key and give a reason. [2]
Show answer
- (a) 7 fields; 8 records.
1 mark each.
- (b) BookID – each value is unique, so it identifies each book (record) exactly.
1 mark: BookID. 1 mark: unique for every record.
Q18Tables, fields, records, primary keys and data types · Core · Paper 2 style · 5 marksTable PATIENTS:PatientID | Name | Age | City | BloodGroup | InsuredP001 | Hina | 34 | Lahore | O+ | TRUEP002 | Kamran | 61 | Karachi | A+ | FALSEP003 | Sana | 8 | Lahore | B+ | TRUEP004 | Imran | 45 | Multan | O+ | TRUEP005 | Zara | 27 | Karachi | AB- | FALSEP006 | Tariq | 72 | Lahore | A+ | TRUEP007 | Nida | 15 | Multan | O- | FALSE
- (a) Give the most suitable data type (text/alphanumeric, character, Boolean, integer, real or date/time) for each field: PatientID, Age, BloodGroup, Insured. [4]
- (b) Explain why Name would not be a suitable primary key. [1]
Show answer
- (a) PatientID text/alphanumeric; Age integer; BloodGroup text/alphanumeric; Insured Boolean.
1 mark each. BloodGroup is not character because some values have more than one character (e.g. AB-).
- (b) Two patients could have the same name, so it would not be unique.
B1.
Q19Tables, fields, records, primary keys and data types · Core · Paper 2 style · 5 marks- (a) Define the terms field, record and primary key. [3]
- (b) A single-table database stores students' details. Suggest a suitable primary key field and explain your choice. [2]
Show answer
- (a) Field: one item of data about each record (a column), e.g. Name. Record: all the data about one item/person (a row). Primary key: a field that holds a unique value for each record, used to identify it.
1 mark each.
- (b) StudentID / admission number – it is given uniquely to each student, so no two records share it.
1 mark: suitable unique identifier field. 1 mark: reason (unique, never repeated, does not change).
Q20Tables, fields, records, primary keys and data types · Core · Paper 2 style · 4 marksTable MOVIES:MovieID | Title | Genre | Minutes | Rating | ReleasedM01 | Sky Riders | Action | 128 | 7.4 | 2021M02 | Quiet Lake | Drama | 104 | 8.1 | 2019M03 | Laugh Out | Comedy | 92 | 6.5 | 2022M04 | Iron Coast | Action | 141 | 6.9 | 2018M05 | Paper Hearts | Drama | 117 | 7.8 | 2023M06 | Zoo Day | Comedy | 85 | 7.1 | 2020
- (a) State the number of fields and records in MOVIES. [2]
- (b) Give the data type of the field Rating. [1]
- (c) Give the name of the primary key field. [1]
Show answer
- (a) 6 fields; 6 records.
1 mark each.
- (b) Real.
B1.
- (c) MovieID.
B1.
Q21Tables, fields, records, primary keys and data types · Core · Paper 2 style · 4 marksA table SCHOOLBUS stores data about buses: BusNo (e.g. LHR-12), Driver, Capacity, AirConditioned, LastService.
- (a) Give the most suitable data type for Capacity, AirConditioned and LastService. [3]
- (b) State which field is most suitable as the primary key. [1]
Show answer
- (a) Capacity integer; AirConditioned Boolean; LastService date/time.
1 mark each.
- (b) BusNo.
B1 – each bus has a unique registration/number.
Q22Tables, fields, records, primary keys and data types · Standard · Paper 2 style · 7 marksTable FLIGHTS:FlightNo | Destination | DepTime | Seats | PricePK301 | Dubai | 06:15 | 12 | 48000PK785 | London | 09:40 | 3 | 210000EK612 | Dubai | 13:05 | 40 | 52000QR605 | Doha | 15:30 | 0 | 61000PK213 | Jeddah | 18:45 | 25 | 95000TK715 | Istanbul | 22:10 | 7 | 120000
- (a) State the number of records in FLIGHTS. [1]
- (b) Give the most suitable data type for each field: FlightNo, DepTime, Seats, Price. [4]
- (c) The airline adds the flight date to the table. Explain why FlightNo alone could then no longer be the primary key. [2]
Show answer
- (a) 6
B1.
- (b) FlightNo text/alphanumeric; DepTime date/time; Seats integer; Price integer (accept real/currency).
1 mark each.
- (c) The same flight number is used every day, so the same FlightNo would appear in many records and would not be unique.
1 mark: same flight number repeats on different dates. 1 mark: primary key must be unique for each record (a new unique field such as a FlightID would be needed).
Q23Tables, fields, records, primary keys and data types · Standard · Paper 2 style · 6 marksTable PRODUCTS:Code | Item | Category | Price | StockS01 | Rice 5 kg | Grocery | 1450.00 | 30S02 | Green tea | Drinks | 380.50 | 0S03 | Cooking oil | Grocery | 2100.00 | 12S04 | Mango juice | Drinks | 220.00 | 45S05 | Soap bar | Household | 95.00 | 80S06 | Lentils 1 kg | Grocery | 420.00 | 0S07 | Washing powder | Household | 650.00 | 18S08 | Mineral water | Drinks | 70.00 | 120
- (a) State the number of fields and records in PRODUCTS. [2]
- (b) Identify the most suitable data type for Price and for Stock, and explain the difference. [3]
- (c) Suggest a validation check for the Stock field. [1]
Show answer
- (a) 5 fields; 8 records.
1 mark each.
- (b) Price real (it has a decimal part such as 380.50); Stock integer (it is a whole number of items).
1 mark: Price real. 1 mark: Stock integer. 1 mark: reason – decimals vs whole numbers.
- (c) Range check – Stock must be 0 or more (and an integer type check).
B1 range check ≥ 0 / type check (whole number).
Q24Tables, fields, records, primary keys and data types · Standard · Paper 2 style · 6 marksAn online electronics store in Dubai designs a table CUSTOMER with these fields: CustomerID, FullName, Email, Phone, DateOfBirth, LoyaltyPoints, Newsletter (yes or no).
- (a) Give the most suitable data type for each of the seven fields. [4]
- (b) Explain why Phone should be stored as text and not as an integer. [2]
Show answer
- (a) CustomerID text/alphanumeric (or integer if numeric only); FullName text; Email text; Phone text; DateOfBirth date/time; LoyaltyPoints integer; Newsletter Boolean.
4 marks for all seven correct; 3 marks for five or six; 2 marks for four; 1 mark for two or three.
- (b) Phone numbers may start with 0 or + and contain spaces or hyphens, which would be lost or not allowed in an integer field; they are never used in calculations.
1 mark: leading zero/+/symbols. 1 mark: not used in calculations.
Q25Tables, fields, records, primary keys and data types · Standard · Paper 2 style · 5 marks- (a) A gym in Islamabad stores data about its members in a database table. Explain why a database table is better than storing the data in separate text files. [2]
- (b) The table has the fields MemberID, Name, MembershipType (Gold, Silver or Bronze), StartDate, MonthlyFee and PersonalTrainer (yes or no). Give a suitable data type and a sample value for MembershipType, StartDate and MonthlyFee. [3]
Show answer
- (a) Data is stored in one structured place with fields and records, so it can be searched and sorted quickly using queries; it reduces duplication and makes updating easier.
1 mark each for any two of: data organised in fields/records; quick searching/sorting with queries; less duplication; easier to update; validation can be applied to fields.
- (b) MembershipType text – 'Gold'; StartDate date/time – 15/03/2026; MonthlyFee real – 4500.00.
1 mark each for a correct type with a suitable value.
Q26Tables, fields, records, primary keys and data types · Standard · Paper 2 style · 5 marksTable PATIENTS:PatientID | Name | Age | City | BloodGroup | InsuredP001 | Hina | 34 | Lahore | O+ | TRUEP002 | Kamran | 61 | Karachi | A+ | FALSEP003 | Sana | 8 | Lahore | B+ | TRUEP004 | Imran | 45 | Multan | O+ | TRUEP005 | Zara | 27 | Karachi | AB- | FALSEP006 | Tariq | 72 | Lahore | A+ | TRUEP007 | Nida | 15 | Multan | O- | FALSE
- (a) Identify the field that contains only one of two possible values and state its data type. [2]
- (b) A new patient record is to be added: P008, Bilal, 39, Karachi, B-, TRUE. State the number of records in the table after the record has been added. [1]
- (c) Explain why the database would reject another new record that also has the PatientID P003. [2]
Show answer
- (a) Insured; Boolean.
1 mark each.
- (b) 8
7 + 1.
- (c) PatientID is the primary key, so every value must be unique; P003 already exists, so the new record would be a duplicate key.
1 mark: PatientID is the primary key. 1 mark: values must be unique / duplicate not allowed.
Q27Tables, fields, records, primary keys and data types · Challenge · Paper 2 style · 8 marksA school in Lahore keeps a single-table database of its library members with these fields:MemberNo, FirstName, FamilyName, Class, DateJoined, FinesOwed, IsTeacher, GradeSample values: M0451, Ali, Raza, 9B, 04/09/2025, 120.00, FALSE, A
- (a) Give the most suitable data type for each field: MemberNo, DateJoined, FinesOwed, IsTeacher, Grade. [5]
- (b) A student suggests using FamilyName as the primary key. Explain why this is not suitable and name the field that should be used. [2]
- (c) Explain why Class is stored as text rather than as an integer. [1]
Show answer
- (a) MemberNo text/alphanumeric; DateJoined date/time; FinesOwed real; IsTeacher Boolean; Grade character.
1 mark each.
- (b) Many members (e.g. brothers and sisters) can share a family name, so the values are not unique; MemberNo should be the primary key.
1 mark: not unique. 1 mark: MemberNo.
- (c) It contains letters as well as digits (e.g. 9B).
B1.
Q28Tables, fields, records, primary keys and data types · Challenge · Paper 2 style · 7 marksTable WEATHER:StationID | City | Country | Rainfall | MaxTempW1 | Karachi | Pakistan | 2.5 | 36.4W2 | Murree | Pakistan | 41.0 | 22.1W3 | Mumbai | India | 88.2 | 31.0W4 | Colombo | Sri Lanka | 64.7 | 30.2W5 | Quetta | Pakistan | 0.0 | 33.8W6 | Dhaka | Bangladesh | 57.3 | 32.6W7 | Lahore | Pakistan | 18.9 | 38.0
- (a) State the number of fields and records in WEATHER. [2]
- (b) The weather service now wants to store a reading for every station every day. Explain why the table design would need to change, and suggest a new primary key. [3]
- (c) Give the data type for Rainfall and for the new date field. [2]
Show answer
- (a) 5 fields; 7 records.
1 mark each.
- (b) StationID would appear in many records (one for each day), so it would no longer be unique; a date field must be added; a new unique field such as ReadingID (a unique number for each reading) should be the primary key.
1 mark: StationID repeats so cannot be primary key. 1 mark: a date field is needed. 1 mark: a new unique key field, e.g. ReadingID.
- (c) Rainfall real; date field date/time.
1 mark each.
Q29Tables, fields, records, primary keys and data types · Challenge · Paper 2 style · 6 marksA sports academy in Colombo stores this data about its athletes in one table:AthleteID | Name | Sport | Coach | CoachPhoneA01 | Nimal | Swimming | Ms Perera | 0771234567A02 | Ayesha | Athletics | Mr Silva | 0719876543A03 | Ravi | Swimming | Ms Perera | 0771234567A04 | Fatima | Squash | Mr Khan | 0765551234
- (a) State the number of fields and records. [2]
- (b) Ms Perera changes her phone number. Explain a problem this table design causes when the data is updated. [2]
- (c) Give the data type for CoachPhone and justify it. [2]
Show answer
- (a) 5 fields; 4 records.
1 mark each.
- (b) Her number is stored in more than one record (A01 and A03), so every copy must be changed; if one is missed, the data becomes inconsistent.
1 mark: data repeated/duplicated in several records. 1 mark: risk of inconsistent data if not all copies are updated (more storage used).
- (c) Text/alphanumeric – it starts with 0 (which would be lost as an integer) and is not used in calculations.
1 mark: text. 1 mark: reason.
Q30Tables, fields, records, primary keys and data types · Challenge · Paper 2 style · 9 marksA cinema's single table SCREENINGS has the fields: ScreeningID, FilmTitle, ScreenNo, StartTime, TicketPrice, SeatsSold, Is3D.
- (a) Give the most suitable data type for each field. [4]
- (b) Explain why FilmTitle is not a suitable primary key, but ScreeningID is. [2]
- (c) Write a query that outputs the FilmTitle and StartTime of all 3D screenings on screen 2. [3]
Show answer
- (a) ScreeningID text/alphanumeric; FilmTitle text; ScreenNo integer; StartTime date/time; TicketPrice real; SeatsSold integer; Is3D Boolean.
4 marks for all seven correct; 3 marks for five or six; 2 marks for four; 1 mark for two or three.
- (b) The same film is shown many times, so FilmTitle is repeated in many records; ScreeningID is given a unique value for every screening.
1 mark: FilmTitle repeats. 1 mark: ScreeningID unique for each record.
- (c) SELECT FilmTitle, StartTimeFROM SCREENINGSWHERE Is3D = TRUE AND ScreenNo = 2;
1 mark: SELECT/FROM; 1 mark: Is3D = TRUE; 1 mark: AND ScreenNo = 2.