ExamBank Scot · Higher Computing Science question bank · All Higher Computing Science questions

Higher Computing Science 2022 Question 12

10 marks · Keys and the data dictionary

When the CarSale table was originally designed, it was suggested that a compound key could have been used. Explain why a compound key would not have been suitable for the CarSale table. Sample data from the CarSale table is shown below. CarSale saleID carReg dateIn year mileage askingPrice sold dateSold salesPersonRef custNo soldPrice 001 KS17 SDD 17/07/2019 2017 2400 15305 Yes 19/09/2019 GA001 1234 14000 002 DD15 LDX 11/10/2019 2015 45512 6000 Yes 22/11/2019 AJ344 1234 5750 003 DG15 KJS 01/03/2021 2015 34069 5000 Yes 26/06/2021 AJ344 7001 4800 004 KS19 AZX 14/08/2021 2019 10033 13655 Yes 19/09/2021 AJ344 7747 13555 005 FF18 PMD 08/12/2021 2019 8238 10800 Yes 28/12/2021 SS002 5414 10500 006 LK16 JSS 07/03/2022 2016 45300 8500 No 007 EF18 FES 10/03/2022 2018 29178 11709 No 008 DD15 LDX 15/03/2022 2015 72130 5000 No 009 KP15 DDS 01/04/2022 2015 34444 7900 Yes 02/05/2022 GA001 3002 7800 010 KS17 SDD 01/04/2022 2017 22452 12000 No 011 PK17 YFK 22/04/2022 2017 19858 22663 No 012 FF17 EES 26/04/2022 2017 14469 10166 No 013 DS17 KRF 02/05/2022 2017 16113 14748 No … … … … … … … … … … … A customer would like to buy a car from the years 2017 or 2018. They want to know the cheapest asking price of the 2017 and the 2018 cars that are currently on sale. This information is shown below. year Cheapest Price 2017 10166 2018 11709 Complete the design of a query that will display the information as shown above. Field(s) and calculation(s) Tables(s) CarSale Search criteria Grouping Sort order year ASC The manager would like to display a list of all cars that have been sold, showing the price difference between the asking price and the sold price. The list should look like this. carReg salesPersonName askingPrice soldPrice Price Difference KP15 DDS Daniel Avery 7900 7800 100 FF18 PMD Deanna Smith 10800 10500 300 KS19 AZX Hosea Jack 13655 13555 100 DD15 LDX Hosea Jack 6000 5750 250 DG15 KJS Hosea Jack 5000 4800 200 KS17 SDD Daniel Avery 15305 14000 1305 … … … … … Write the SQL statement that would create this list. The asking price of all cars with mileage of 10 000 or less have to be increased by 10%. Write the SQL statement that would make these changes. A car dealership uses a relational database to store the following information in three tables as shown below. CarSale Customer SalesPerson saleID carReg dateIn year mileage askingPrice sold dateSold salesPersonRef* customerNo* soldPrice customerNo firstName surname contactNo salesPersonRef salesPersonName

Marking scheme

• saleID is able to uniquely identify the record • The primary keys from the other two tables would not uniquely identify a car for sale. • There would be no customer number or salesPersonRef until a sale had been made and the values in a compound key cannot be left empty. 1 mark for any one bullet Field(s) and calculation(s) year, min(askingPrice) AS ‘Cheapest Price’ Search criteria year=2017 OR year=2018 AND Sold = ‘No’ Grouping year 1 mark for each row Allow use of minimum in design of query. Correct syntax is not required in design. • fields and alias • calculation (askingPrice - soldPrice) • tables and equi-join • sold = ‘Yes’; 1 mark for each bullet SELECT carReg, salesPersonName, askingPrice, soldPrice, (askingPrice-soldPrice) AS [Price Difference] FROM CarSale, SalesPerson WHERE CarSale.salesPersonRef = SalesPerson.salesPersonRef and sold = ‘Yes’; Sold=’Yes’ could be established several other ways e.g. soldPrice is not null • UPDATE CarSale and WHERE mileage <=10000 • SET askingPrice = askingPrice * 1.10 1 mark for each bullet Award 0 marks for first bullet if there are any additional SQL clauses. UPDATE CarSale SET askingPrice = askingPrice * 1.10 WHERE mileage <=10000; Or SET askingPrice=askingPrice +askingPrice/10

Previous question: Higher Computing Science 2022 Question 11

Next question: Higher Computing Science 2022 Question 13