VERSION 1 COMPSCI 280 THE UNIVERSITY OF AUCKLAND SECOND SEMESTER, 2015 Campus: City COMPUTER SCIENCE Enterprise Software Development (Time allowed: 40 minutes) NOTE: Enter your name and student ID into the Teleform sheet FIRST. THEN: Attempt all questions! All questions have ONE correct answer. DO NOT tick two answers as correct for the same question. If you believe that there is an error in a question (multiple correct answers or no correct answer), select the answer you believe was intended as the correct one and contact the test room supervisor after the test. Keep your question book. Writing on the question book will not be marked. Use of calculators is NOT permitted. Good luck!
VERSION 1 2 COMPSCI 280 1. Consider a database table with n records. If the table has a primary key, lookup of a key value can be done in (at worst) A. O(n 2 ) B. O( n) C. O(n log n) D. O(log n) E. O(n) 2. Which of the following functions would you find in a HAVING clause but not in a WHERE clause? A. LOWER() B. CONCAT() C. ABS() D. SIN() E. COUNT() 3. You PREPARE a prepared statement in PHPMyAdmin s SQL tab for later execution, hit GO, and PHPMyAdmin returns no error. You then try to EXECUTE the statement, but this returns an error. You then repeat the same operations on the command line client, and everything works. What is the problem? A. Parameters in PHPMyAdmin are defined on a different tab. B. PHPMyAdmin executes each query in an individual session. C. PHPMyAdmin cannot handle prepared statements. D. The statement violates a foreign key constraint in PHPMyAdmin. E. There is a bug in PHPMyAdmin. 4. Name a drawback of having multiple keys in a SQL table with a large number of records. A. The table cannot have an autoincrement field. B. Inserts into the table are slower. C. Simplified INSERT statements will not work. D. It is not clear what the primary key is. E. SELECT queries with WHERE clauses are slower.
VERSION 1 3 COMPSCI 280 5. Under normal standard configuration, what is the value of the expression (NULL=NULL) in SQL? A. TRUE B. 0 C. NULL D. 1 E. FALSE 6. When would you use table aliases? A. When the result set of a query needs to return records that contain the same column twice, but with values from different rows. B. When the result set of a query needs to return columns with identical names from two different tables. C. When the result set of a query needs to return records from a table in another database. D. When the result set of a query needs to return records from two tables with the same name. E. When the result set of a SELECT query will be used to create a view, and we want to be able to update records in the view. 7. Which of the following queries is most likely to succeed on a view vw CityPairs created with the SQL statement CREATE VIEW vw CityPairs FROM SELECT c1.name AS City 1, c2.name AS City 2 FROM City c1, City c2 WHERE c1.country!= c2.country AND c2.name > c1.name? A. INSERT INTO vw CityPairs ( City 1, City 2 ) VALUES ( Wellington, New York ) B. DELETE FROM vw CityPairs WHERE City 1 = Auckland AND City 2 = Beijing C. DELETE FROM vw CityPairs WHERE City 1 = Auckland D. SELECT * FROM vw CityPairs WHERE City 1 = Auckland E. UPDATE vw CityPairs SET City 1 = Akarana WHERE City 1 = Auckland
VERSION 1 4 COMPSCI 280 8. Consider a trigger created with a statement starting as follows: CREATE TRIGGER x BEFORE DELETE ON y... Which of the following syntax elements would you not expect to find inside the rest of the statement? A. INSERT B. OLD C. UPDATE D. FOR EACH ROW E. NEW 9. Consider the following pairs of queries (separated here by a semicolon). Which pair could you use in a UNION statement? A. SELECT * FROM City, Country WHERE City.country = Country.id AND Country.name = NZ ; SELECT name FROM City, Country WHERE City.country = Country.id AND Country.name = Australia B. SELECT name FROM Country WHERE Country.id < 10; SELECT City.name, Country.name FROM City, Country WHERE City.country = Country.id AND (Country.name = Australia OR Country.name = NZ ) C. SELECT name FROM City WHERE City.country = 11; SELECT name,country FROM City WHERE City.country = 2 D. SELECT name FROM Country WHERE City.country = 11; UPDATE Country SET name= Gnophtublinok WHERE City.country = 2 E. SELECT City.name FROM City, Country WHERE City.country = Country.id AND Country.name = NZ ; SELECT City.name FROM City, Country WHERE City.country = Country.id AND Country.name = Australia 10. You have a table A with a primary key x and a table B with a field y that has a foreign key constraint referencing field x in A. Assume that the values of x in records of A include only 2, 4, 5 and 9, and that the only values of y in B are 4 and 9. Assume that all other fields in either table may be NULL. Which of the following query sequences will fail? A. INSERT INTO B (y) VALUES (2); UPDATE A SET x=5 WHERE x=2 B. INSERT INTO B (y) VALUES (2); UPDATE A SET x=6 WHERE x=5 C. UPDATE B SET y=2; UPDATE A SET x=5 WHERE x=4 D. DELETE FROM B WHERE y=4; UPDATE A SET x=5 WHERE x=4 E. INSERT INTO B (y) VALUES (2); UPDATE A SET x=5 WHERE x=7
VERSION 1 5 COMPSCI 280 11. In a SELECT query using a GROUP BY X for some field X, you expect the result set to contain: A. all rows with the same value of X grouped together in successive records, but not necessarily in sorted order B. all rows with the same value of X grouped together in successive records, for those values of X that meet the criteria in the HAVING clause C. all rows for all values of X, sorted (GROUP BY is an alias for ORDER BY) D. one row for each distinct value of X E. all rows with the same value of X grouped together in successive records, in sorted order 12. You design a SQL table for a database expected to live 10 years. You know that it will never have more than 100 records, but that it will experience frequent inserts and deletes - around 250000 of each operation per day. You also know that its autoincrement primary key will be referenced as a foreign key by a large number of other tables in the database, so efficient storage is important and you want to keep your primary key field as small as possible. What data type would you choose for the primary key? A. a two byte SMALLINT UNSIGNED B. a four byte INT UNSIGNED C. a one byte TINYINT D. a three byte MEDIUMINT UNSIGNED E. a VARCHAR(100) 13. To implement a one-to-many relationship between the records of two tables, you need: A. a view B. an outer join C. another table D. foreign key fields in both tables E. a foreign key in the records of the detail table 14. What could happen if you update multiple tables in a single SQL UPDATE statement? A. Foreign key constraint violations could occur if fields do not update in the required order. B. The query will fail if the tables have a left join. C. There could be a trigger loop. D. Field names in the SET clause could be ambiguous. E. There could be a deadlock if the update of one table causes records in one of the other tables to be deleted.
VERSION 1 6 COMPSCI 280 15. You have a master-detail relationship between two tables in a SQL DB which is enforced by a foreign key constraint. Which of the following is true? A. The detail table s primary key supplies the foreign key values to the master table, which references them in each record. B. The detail table supplies the foreign key values, the master table implements the foreign key and references a value from the detail table in the foreign key in each record. C. The master table s primary key is also the detail table s primary key. D. The master table s foreign key is the detail table s primary key. E. The master table supplies the foreign key values, the detail table implements the foreign key and references a value from the master table in the foreign key in each record. 16. Which of the following column data types would you use to store the codes of University of Auckland courses including semester and campus (e.g., MAGIC101S2C)? A. ALPHA(16) B. VARCHAR(11) C. VARCHAR(255) D. ANUM(16) E. TO UPPER(16) 17. Which of the following queries does not affect the structure of a database? A. CREATE VIEW B. DROP TABLE C. ALTER TABLE D. DELETE FROM E. DROP PROCEDURE
VERSION 1 7 COMPSCI 280 18. Consider a table Species which stores the species of animals (such as Lion, Elephant, Mouse, etc.) in a field name VARCHAR(255) along with a unique primary key speciesid INT UNSIGNED NOT NULL. Further consider a table Animal which stores the name VARCHAR(255) and weight FLOAT of an animal (such as Jumbo, Mickey, etc.) along with a field species containing the animal s speciesid as per Species table. You execute the query: SELECT Animal.name AS Name, Animal.weight AS Weight, Species.name AS Species FROM Species LEFT JOIN Animal ON Animal.species = Species.speciesId. In which column(s) would you expect NULL values? A. Name and Species B. Name and Weight C. Species and Weight D. Species E. none
VERSION 1 8 COMPSCI 280 Working page 1
VERSION 1 9 COMPSCI 280 Working page 2