THE UNIVERSITY OF AUCKLAND

Similar documents
Basic SQL. Basic SQL. Basic SQL

Basic SQL. Dr Fawaz Alarfaj. ACKNOWLEDGEMENT Slides are adopted from: Elmasri & Navathe, Fundamentals of Database Systems MySQL Documentation

Data Modelling and Databases. Exercise Session 7: Integrity Constraints

Constraints. Primary Key Foreign Key General table constraints Domain constraints Assertions Triggers. John Edgar 2

Database Systems: Design, Implementation, and Management Tenth Edition. Chapter 7 Introduction to Structured Query Language (SQL)

Databases and SQL programming overview

Daffodil DB. Design Document (Beta) Version 4.0

Sql Server Syllabus. Overview

Chapter 4. Basic SQL. SQL Data Definition and Data Types. Basic SQL. SQL language SQL. Terminology: CREATE statement

MySQL. A practical introduction to database design

Mysql Create Table With Multiple Index Example

Where are we? Week -4: Data definition (Creation of the schema) Week -3: Data definition (Triggers) Week -1: Transactions and concurrency in ORACLE.

Querying Data with Transact SQL

Oral Questions and Answers (DBMS LAB) Questions & Answers- DBMS

Intermediate SQL ( )

5. SQL Query Syntax 1. Select Statement. 6. CPS: Database Schema

Chapter 4. Basic SQL. Copyright 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley

MANAGING DATA(BASES) USING SQL (NON-PROCEDURAL SQL, X401.9)

Announcements (September 18) SQL: Part II. Solution 1. Incomplete information. Solution 3? Solution 2. Homework #1 due today (11:59pm)

Exam code: Exam name: Database Fundamentals. Version 16.0

CSCU9Q5 Introduction to MySQL. Data Definition & Manipulation (Over ~two Lectures)

SQL: Part II. Announcements (September 18) Incomplete information. CPS 116 Introduction to Database Systems. Homework #1 due today (11:59pm)

SQL functions fit into two broad categories: Data definition language Data manipulation language

Reference: W3School -

SQL Functionality SQL. Creating Relation Schemas. Creating Relation Schemas

Copyright 2016 Ramez Elmasri and Shamkant B. Navathe

Unit Assessment Guide

Simple Quesries in SQL & Table Creation and Data Manipulation

Chapter 7. Introduction to Structured Query Language (SQL) Database Systems: Design, Implementation, and Management, Seventh Edition, Rob and Coronel

Language. f SQL. Larry Rockoff COURSE TECHNOLOGY. Kingdom United States. Course Technology PTR. A part ofcenqaqe Learninq

Principles of Data Management

DB2 MOCK TEST DB2 MOCK TEST I

Unit 27 Web Server Scripting Extended Diploma in ICT

Data and Tables. Bok, Jong Soon

EGCI 321: Database Systems. Dr. Tanasanee Phienthrakul

DATA AND SCHEMA MODIFICATIONS CHAPTERS 4,5 (6/E) CHAPTER 8 (5/E)

SQL: Data Definition Language. csc343, Introduction to Databases Diane Horton Fall 2017

Chapter 3:Spatial Query Languages 3.1 Standard Database Query Languages 3.2 Relational Algebra 3.3 Basic SQL Primer 3.4 Extending SQL for Spatial

CS 327E Lecture 2. Shirley Cohen. January 27, 2016

Databases II: Microsoft Access

IBM DB2 UDB V7.1 Family Fundamentals.

For the Dorm Energy Monitoring DB design, some constraints are given and some are absent. You are asked to fill in some of these absent constraints.

Querying Data with Transact-SQL (20761)

Concepts of Database Management Seventh Edition. Chapter 4 The Relational Model 3: Advanced Topics

Midterm Exam #2 (Version A) CS 122A Winter 2017

Querying Data with Transact-SQL

Data about data is database Select correct option: True False Partially True None of the Above

Introduction to SQL. ECE 650 Systems Programming & Engineering Duke University, Spring 2018

SQL: Part II. Introduction to Databases CompSci 316 Fall 2018

CSE 530A. Inheritance and Partitioning. Washington University Fall 2013

GITA 338: Spatial Information Processing Systems

T-SQL Training: T-SQL for SQL Server for Developers

CS121 MIDTERM REVIEW. CS121: Relational Databases Fall 2017 Lecture 13

SynApp2 Walk through No. 1

EE221 Databases Practicals Manual

Enhanced Data Models for Advanced Applications. Active Database Concepts

Announcements. Multi-column Keys. Multi-column Keys (3) Multi-column Keys. Multi-column Keys (2) Introduction to Data Management CSE 414

SQL STRUCTURED QUERY LANGUAGE

Exam Actual. Higher Quality. Better Service! QUESTION & ANSWER

Creating databases using SQL Server Management Studio Express

Table of Contents. PDF created with FinePrint pdffactory Pro trial version

Querying Data with Transact-SQL

Introduction. Sample Database SQL-92. Sample Data. Sample Data. Chapter 6 Introduction to Structured Query Language (SQL)

Think about these queries for exam

Announcements. Multi-column Keys. Multi-column Keys. Multi-column Keys (3) Multi-column Keys (2) Introduction to Data Management CSE 414

Interview Questions on DBMS and SQL [Compiled by M V Kamal, Associate Professor, CSE Dept]

Querying Data with Transact SQL Microsoft Official Curriculum (MOC 20761)

MTA Database Administrator Fundamentals Course

SQL. Often times, in order for us to build the most functional website we can, we depend on a database to store information.

Private Institute of Aga NETWORK DATABASE LECTURER NIYAZ M. SALIH

1z Oracle Database SQL Expert

MTAT Introduction to Databases

Oracle Syllabus Course code-r10605 SQL

A practical introduction to database design

3ISY402 DATABASE SYSTEMS

Course Modules for MCSA: SQL Server 2016 Database Development Training & Certification Course:

SQL Interview Questions

INDEX. 1 Basic SQL Statements. 2 Restricting and Sorting Data. 3 Single Row Functions. 4 Displaying data from multiple tables

What is SQL? Toolkit for this guide. Learning SQL Using phpmyadmin

CSE 344 JANUARY 5 TH INTRO TO THE RELATIONAL DATABASE

2.9 Table Creation. CREATE TABLE TableName ( AttrName AttrType, AttrName AttrType,... )

MTAT Introduction to Databases

Carnegie Mellon Univ. Dept. of Computer Science /615 - DB Applications. Today's Party. Example Database. Faloutsos/Pavlo CMU /615

Mysql Create Table Example Primary Key Foreign

Database Programming with PL/SQL

SQL Server. Lecture3 Cascading referential integrity constraint

Simple For each base table and order clause

Introduction to Data Management CSE 414

Chapter 8: Working With Databases & Tables

COMP102: Introduction to Databases, 20

Performance Optimization for Informatica Data Services ( Hotfix 3)

Introduction to SQL Server 2005/2008 and Transact SQL

Lecture 07. Spring 2018 Borough of Manhattan Community College

Database Management System Dr. S. Srinath Department of Computer Science & Engineering Indian Institute of Technology, Madras Lecture No.

MySQL. Rheinisch-Westfälische Technische Hochschule Aachen Data Management and Data Exploration Group Univ.-Prof. Dr. rer. nat.

Mahathma Gandhi University

Slides by: Ms. Shree Jaswal

Follow these steps to get started: o Launch MS Access from your start menu. The MS Access startup panel is displayed:

Tool/Web URL Features phpmyadmin. More on phpmyadmin under User Intefaces. MySQL Query Browser

Querying Microsoft SQL Server 2014

Transcription:

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