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 a UNIQUE constraint on a column guarantee?
ANo two rows have the same non-NULL value in that column
BThe column automatically becomes the primary key of the table
CThe column values are sorted
DThe column cannot be changed after insert
2.Easy
Which operator is used for simple text pattern matching in a WHERE clause?
ALIKE
BSIMILAR
CMATCH
DCONTAINS
3.Easy
What does COMMIT do in a transaction?
ALocks the whole database
BUndoes all changes made since the transaction began
CMakes all changes of the transaction permanent
DStarts a new table
4.Medium
A LEFT JOIN returns:
AAll rows from the left table and matching rows from the right, with NULLs where there is no match
BAll rows from the right table only
COnly matching rows from both tables
DRows that match in neither table
5.Medium
An employees table has a column manager_id that refers to another employee. How do you list each employee next to their manager's name?
AUse GROUP BY manager_id only
BCombine the table with itself using UNION ALL and a WHERE filter
CJoin the employees table with itself using two aliases
DCreate a second copy of the table on disk
6.Medium
The orders table has 5 rows, each referring to an existing customer. The customers table has 3 rows. How many rows does an INNER JOIN on customer_id return?
A3
B5
C15
D8
7.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?
AIndexes cannot be created on Boolean columns
BThe optimiser never uses indexes in WHERE clauses
CTRUE is treated as NULL by the index
DMost rows match, so a full table scan is cheaper than many index lookups
8.Hard
Scores are 90, 90 and 80. Which values does RANK() OVER (ORDER BY score DESC) give?
A1, 1, 3
B1, 2, 3
C1, 1, 2
D2, 2, 3
Answer key
1. A · No two rows have the same non-NULL value in that column
2. A · LIKE
3. C · Makes all changes of the transaction permanent
4. A · All rows from the left table and matching rows from the right, with NULLs where there is no match
5. C · Join the employees table with itself using two aliases
6. B · 5
7. D · Most rows match, so a full table scan is cheaper than many index lookups
8. A · 1, 1, 3
Full step-by-step solutions: practise this topic on examproblems.com.