ExamBank Scot · Higher Computing Science question bank · All Higher Computing Science questions
7 marks · Keys and the data dictionary
Explain why a compound key of customerID and itemID would mean that the table is not fit for purpose. The Rental table was re‑designed with a primary key called rentalID. Extracts from the three tables are shown below. Rental rentalID customerID itemID startDate noOfDays REN14 AM232 EK001 01/08/2021 14 REN1 AM974 CB001 26/06/2021 14 REN2 AM974 KB001 30/06/2021 3 … … … … … Customer customerID firstName surname hotel resort AM232 Amy Moore Esmerelda Caleta AM974 Amy Moore Labranda Jandia DR734 Darcia Rycroft Arenas Corralejo … …. … … … Item itemID itemType itemModel dailyRentalPrice CB001 Children’s buggy Basic £6.00 CB002 Children’s buggy Mid £7.00 CB003 Children’s buggy Deluxe £9.00 EK001 Kettle Mid £4.00 IR001 Iron Mid £3.00 KB001 Kid’s bike Basic £14.00 … … … … A list is required to show details of all rentals with a start date in July 2021. The list should display the calculated rental cost for each rental, as shown below. customerID itemType startDate Rental Cost JS001 Manual wheelchair 02/07/2021 £32.00 JS003 Road bike 04/07/2021 £40.00 JS003 Kid’s bike 04/07/2021 £30.00 DR734 Mobility scooter 05/07/2021 £126.00 DR734 Kid’s bike 06/07/2021 £84.00 DR734 Iron 07/07/2021 £6.00 AM974 Road bike 08/07/2021 £42.00 KW001 Manual wheelchair 10/07/2021 £112.00 JS003 Kid’s bike 10/07/2021 £15.00 KW001 Kettle 12/07/2021 £48.00 RB435 Mobility scooter 15/07/2021 £252.00 Design a query to produce this sorted output. Field(s) and calculation(s) Tables(s) and query Search criteria Grouping Sort order A query was created to display the highest daily rental price. This query was saved as ‘MaxRental’. Max daily rental 23.00 Using the ‘MaxRental’ query, complete the SQL statement below to display the item type and item model of any item matching this highest price. SELECT itemType, itemModel A holiday rental shop rents a range of items to customers. It uses a relational database consisting of three linked tables storing data on items, customers and rentals. When initially designing the Rental table for this database, the primary key was designed using a compound key of customerID and itemID. Rental customerID* itemID* startDate noOfDays An example of the data to be stored in the Rental table is shown below. Rental customerID itemID startDate noOfDays AM974 CB001 26/06/2021 14 AM974 KB001 30/06/2021 3 DR734 MS003 05/07/2021 7 AM974 RB002 30/06/2021 3 JS003 KB002 04/07/2021 2 JS003 KB002 10/07/2021 1 JS003 RB001 04/07/2021 2 KW001 WH001 10/07/2021 14 RB435 MS003 15/07/2021 14 SP234 CB001 02/08/2021 7 DR734 KB001 06/07/2021 6 DR734 IR001 07/07/2021 2 … … … …
A customer may rent the same item more than once (which would not be unique). Field(s) and Calculation(s) • Use of three fields customerID, itemType and startDate, and the calculated field (noOfDays * dailyRentalPrice) Tables • Two tables i.e. Rental, Items Search Criteria • Use of complex condition OR of wildcard for July 2020 dates Sort order • startDate with correct sort order 1 mark for each bullet Equi-join not needed in design. Search criteria could be expressed as startDate>=“01/07/2020” AND startDate<=“31/07/2020” Allow use of # around date. As SQL defaults to sorting by ascending order, ASCs does not need to be specified. Example answer Field(s) and calculation(s) customerID, itemType, startDate, (noOfDays * dailyRentalPrice) Tables(s) and query Rental, Item Search criteria AND startDate LIKE "*/07/2020" OR AND startDate LIKE "%/07/2020" (AND Item.itemID = Rental.itemID AND Customer.customerID = Rental.customerID) Grouping Sort order startDate ASC • FROM clause includes Item and MaxRental • WHERE clause is dailyRentalPrice = [Max daily rental] Example answer SELECT itemType, itemModel FROM Item, MaxRental WHERE dailyRentalPrice = [Max daily rental];
Previous question: Higher Computing Science 2021 Question 12