For teachers: free to print, copy and use in class. Every new worksheet has new values and its own answer key. A link to ExamProblems on your course page is appreciated.
Name: ____________________ Date: ____________
1.Easy
What does GROUP BY do in a query?
APuts rows with the same values into groups so aggregates are computed per group
BRemoves rows with NULL values
CJoins two tables on their common columns
DSorts the rows of the result alphabetically
2.Easy
What is a candidate key?
AA minimal set of columns that uniquely identifies each row
BA set of columns shared between two tables to link their rows
CAny column that contains NULL values
DA column that is waiting to become a foreign key
3.Easy
What does a UNIQUE constraint on a column guarantee?
ANo two rows have the same non-NULL value in that column
BThe column values are sorted
CThe column automatically becomes the primary key of the table
DThe column cannot be changed after insert
4.Medium
Which query returns the number of different cities in the customers table?
ASELECT COUNT(city) FROM customers GROUP BY city
BSELECT SUM(DISTINCT city) FROM customers
CSELECT DISTINCT COUNT(city) FROM customers
DSELECT COUNT(DISTINCT city) FROM customers
5.Medium
Why can a table have only one clustered index?
AThe SQL standard forbids more than one index on a table
BThe rows can be stored physically in only one order
CClustered indexes can only be on the primary key
DClustered indexes use too much memory
6.Medium
A table has rows where col is NULL. Which rows does WHERE col = NULL return?
AAll rows of the table
BNo rows, because the comparison is unknown
CAn error in every database
DOnly the rows where col is NULL, as with IS NULL
7.Hard
What does the following return: SELECT name FROM students WHERE grade > (SELECT AVG(grade) FROM students)?
AStudents with the highest grade only
BThe average grade of all students
CStudents with a grade above the average grade
DAn error because subqueries are not allowed in WHERE
8.Hard
A table has a million rows and a Boolean column is_active that is TRUE for 95% of them. Why might the optimiser ignore an index on is_active for WHERE is_active = TRUE?
AMost rows match, so a full table scan is cheaper than many index lookups
BIndexes cannot be created on Boolean columns
CTRUE is treated as NULL by the index
DThe optimiser never uses indexes in WHERE clauses
Answer key
1. A · Puts rows with the same values into groups so aggregates are computed per group
2. A · A minimal set of columns that uniquely identifies each row
3. A · No two rows have the same non-NULL value in that column
4. D · SELECT COUNT(DISTINCT city) FROM customers
5. B · The rows can be stored physically in only one order
6. B · No rows, because the comparison is unknown
7. C · Students with a grade above the average grade
8. A · Most rows match, so a full table scan is cheaper than many index lookups
Full step-by-step solutions: practise this topic on examproblems.com.