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

Higher Computing Science 2024 Question 13

8 marks · UPDATE, DELETE and INSERT

The number of oranges in stock has increased by 20. Write the SQL statement for a single query which would correctly change the quantity of oranges. Previously, the shop sold items supplied by private sellers. The shop has now decided to only sell items supplied by local farmers or wholesalers. The supplierRef of private sellers start with the letter P. Write an SQL statement to remove the details of all private sellers from the database. The profit that an item makes is calculated by subtracting the price the item is bought for from the price that the item sells for. The shop would like to know the largest profit for fruits and vegetables. The largest profit should be listed first. The expected output is shown below. type Profit Veg 0.08 Fruit 0.07 Design the SQL statement to produce this output. Field(s) and calculation(s) Table(s) Search criteria Grouping Sort order A relational database is used to store details of items for sale in a fruit and vegetable shop and of the shop’s suppliers in linked tables. Sample data from two tables is shown below. Item itemID itemName type buyingPrice sellingPrice quantity supplierRef 145 Gala apples Fruit 0.40 0.44 60 F96 146 Iceberg lettuce Veg 0.52 0.60 45 F216 147 Satsuma Fruit 0.30 0.37 52 W125P 148 Red pepper Veg 0.48 0.50 76 F216 149 Organic banana Fruit 0.17 0.23 104 W984 150 Cauliflower Veg 0.93 0.95 34 F216 151 Orange Fruit 0.85 0.89 23 W87 … … … … … … … Supplier supplierRef supplierName address W87 FV Wholesale 136 Main Street F216 Sunnybank Sunnybank Road P1982 J Barrow 96 Hillview Street W984 Fruit Direct 26 Glasgow Road F1982 Appletree Farm Appletree Way F96 Smyth’s Farm Drovers Brae W125P M White 42 Nevis Crescent … … …

Marking scheme

• Correct UPDATE syntax with SET and WHERE in correct order with suitable condition • Correct calculation Example answer: UPDATE Item SET quantity = quantity + 20 WHERE itemName = “Orange” Allow: WHERE itemid = 151 • DELETE FROM Supplier with WHERE supplierRef • LIKE with wildcard after P Example answer: DELETE FROM Supplier WHERE supplierRef LIKE “P%” Allow Access wildcard * • Type field and calculation with alias • MAX function • Table and grouping • Sort using calculation with function/alias DESC Do not award bullet 1 if additional fields in Fields & Calculations Do not double penalise in bullet 4 if incorrect calculation (from bullet 1) is repeated Ignore fruit or veg in search criteria Example answer: Field(s) and calculation(s) type, MAX(sellingPrice-buyingPrice) as Profit Table(s) Item Search criteria Grouping type Sort Order MAX(sellingPrice-buyingPrice) OR Profit DESC

Previous question: Higher Computing Science 2024 Question 12

Next question: Higher Computing Science 2024 Question 14