ExamBank Scot · AH Computing Science question bank · All AH Computing Science questions
13 marks · Data dictionaries
Explain the impact of the chosen data types and sizes in the Member table on both the implementation and testing of the database. Sample data for the Member, Class and Enrolment tables is shown below. Member memberID firstName surname email dateOfBirth M001 John Doe john.doe@example.com 1990‑05‑15 M002 Jane Smith jane.smith@example.com 1985‑10‑20 M003 Alice Brown alice.brown@example.com 2000‑03‑12 M004 Bob Johnson bob.johnson@example.com 1998‑07‑04 M005 Charlie Lee charlie.lee@example.com 1992‑11‑11 M006 Emma Wilson emma.wilson@example.com 2001‑08‑18 Class classID className category capacity cost CLS101 Yoga Basics Fitness 15 50 CLS102 Advanced Painting Art 10 75 CLS103 Photography 101 Photography 20 100 CLS104 Guitar for Beginners Music 25 55 CLS105 Fitness Bootcamp Fitness 30 80 CLS106 Creative Writing Literature 15 65 Enrolment enrolCode memberID classID enrolDate paid startDate E001 M001 CLS101 2024‑11‑01 25 2024‑11‑01 E002 M001 CLS102 2024‑10‑01 50 2024‑10‑01 E003 M002 CLS106 2024‑11‑16 30 2024‑11‑15 E004 M003 CLS104 2024‑10‑06 30 2024‑10‑05 E005 M005 CLS105 2024‑10‑12 40 2024‑10‑10 E006 M006 CLS101 2024‑11‑01 10 2024‑11‑01 Making use of the IN operator, write the SQL query needed to display details of classes that do not have any enrolments. Both queries below can be used to display a list of members who are enrolled in classes. Query 1 SELECT memberID FROM Enrolment WHERE classID = ANY ( SELECT classID FROM Class ); Query 2 SELECT memberID FROM Enrolment WHERE EXISTS ( SELECT classID FROM Class WHERE Class.classID = Enrolment.classID ); Compare the use of the ANY and EXISTS operators in the two queries above. In each case, you should consider what result(s) the subquery returns and how the outer query uses those results. The Member table is to be removed from the database. Write the SQL statement to implement this. With reference to relationship participation, explain the impact of the SQL statement in part (i). Members can access a website that allows them to search for classes that match the category entered. An extract of the form code for the search page is shown below. … <form action="searchCategory.php" method="GET"> <h2>Search for a category</h2> <p>Category name:</p> <input type="text" id="category" name="category" required> <input type="submit" value="Search"> </form> … Explain why the GET method is appropriate for this form. Describe one additional type of data validation for the category name entry. After it has been in use for a month, members report that the search functionality is returning inaccurate search results. State the type of maintenance that would be required in this situation. Justify your answer. A community centre offers online classes in a range of subjects. Details of members, classes and enrolments are stored in three tables of a relational database. The data dictionary showing the design of the Member table is shown below. Attribute Name Key Type Size Required Validation memberID PK varchar 4 yes firstName varchar 30 yes surname varchar 40 yes email varchar 200 yes dateOfBirth date no
Possible answers include: • use of varchar(200) for the email field ensures no overly long or inappropriate data is entered • use of varchar(4) for the PK memberID would ensure that the values stored are meaningful but would require more memory than equivalent 4 digit integer values • use of varchar for the PK memberID may be more difficult to keep track than use of integer data type that can be auto- incremented • indicating data types and sizes used means that appropriate test data values can be generated to ensure that, for example, only valid date values can be entered and excessively long memberIDs would be rejected • use of varchar for several fields allows variable-length string values to be stored with no overheads or padding. This means that only the characters entered (up to the stated maximum number of characters) are stored and use of memory is efficient since there is no need to store unnecessary characters • efficient use of the data type varchar will impact on database performance by improving query efficiency and reducing processing time Award 1 mark each for any two relevant points that refer to Implementation and/or Testing. SELECT className, category FROM Class WHERE classID NOT IN ( SELECT classID FROM Enrolment ); Award 1 mark for correct use of IN with classID and NOT Award 1 mark for subquery with classID NOTE: Do not penalise if fields used in the outer SELECT clause are not an exact match for those in the solution. Query 1 (using ANY) • the subquery executes and returns a list of all classIDs found in the Class table • the outer query then checks each Enrolment.classID to see if it matches any value in that list; if it does, the corresponding memberID is returned • this means that the subquery must execute in full and the outer query must then perform a full scan of the set of results returned by the subquery Query 2 (using EXISTS) • the subquery is executed for each row of the Enrolment table to check whether the subquery returns a true or false value a value of true indicates that the Enrolment.classID of the current row has been matched with a classID from the Class table; when this is the case, the corresponding memberID is returned • this means that the EXISTS comparison stops evaluating the subquery as soon as a suitable match is found Award 1 mark for referring to results returned by each subquery. Award 1 mark for referring to how results of subquery are processed by the outer query with the ANY operator. Award 1 mark for referring to how results of subquery are processed by the outer query with the EXISTS operator. DROP TABLE Member; Enrolment has mandatory participation in its relationship with Member. As a result, deletion of the Member would not be permitted. Note: response must describe the impact of the SQL statement and must refer to relationship participation of Member and Enrolment • GET is suitable as the data submitted would not be sensitive data • using GET allows the search to be bookmarked for future access Award 1 mark for either bullet point. • use minlength and maxlength attributes to add a length check • use SELECT instead of INPUT to generate a drop down list which would restrict the choices available Award 1 mark for accurate description of any one way to improve the input validation. Note: Range check is not appropriate in this situation. • corrective maintenance • since the search function is returning inaccurate results, this needs to be investigated and errors found need to be fixed Award 1 mark for corrective maintenance. Award 1 mark for explanation.