1.Easy
What is a composite key?
- AA key that is generated by the database
- BA key stored in a separate table
- CA key made up of two or more columns
- DA key that allows duplicate values
2.Easy
What is a surrogate key?
- AA key made from real-world data such as an email address
- BA key that is only used in views
- CAn artificial identifier with no business meaning, such as an auto-increment id
- DA key that refers to another table
3.Easy
What does WHERE country IN ('NL', 'BE', 'DE') do?
- AKeeps rows whose country is not in the list
- BSorts rows in the order of the list
- CKeeps rows whose country value contains all three codes at once
- DKeeps rows whose country equals any value in the list
4.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?
- ACreate a second copy of the table on disk
- BJoin the employees table with itself using two aliases
- CCombine the table with itself using UNION ALL and a WHERE filter
- DUse GROUP BY manager_id only
5.Medium
Which query returns the number of different cities in the customers table?
- ASELECT SUM(DISTINCT city) FROM customers
- BSELECT COUNT(DISTINCT city) FROM customers
- CSELECT DISTINCT COUNT(city) FROM customers
- DSELECT COUNT(city) FROM customers GROUP BY city
6.Medium
Second normal form (2NF) removes:
- AAll NULL values
- BPartial dependencies of non-key columns on part of a composite key
- CForeign keys
- DTransitive dependencies between non-key columns via another non-key column
7.Hard
What does the following return: SELECT name FROM students WHERE grade > (SELECT AVG(grade) FROM students)?
- AStudents with a grade above the average grade
- BStudents with the highest grade only
- CThe average grade of all students
- DAn error because subqueries are not allowed in WHERE
8.Hard
Which SQL feature is best suited to finding every employee below a manager in an organisation tree of unknown depth?
- AA UNIQUE constraint on manager_id
- BA single self-join of the employees table on manager_id
- CA recursive common table expression (WITH RECURSIVE)
- DA GROUP BY on manager_id
Answer key
- 1. C · A key made up of two or more columns
- 2. C · An artificial identifier with no business meaning, such as an auto-increment id
- 3. D · Keeps rows whose country equals any value in the list
- 4. B · Join the employees table with itself using two aliases
- 5. B · SELECT COUNT(DISTINCT city) FROM customers
- 6. B · Partial dependencies of non-key columns on part of a composite key
- 7. A · Students with a grade above the average grade
- 8. C · A recursive common table expression (WITH RECURSIVE)
Full step-by-step solutions: practise this topic on examproblems.com.