Databases & SQL worksheet with answers

Free printable Databases & SQL worksheet: 8 problems from easy to exam level, with an answer key. Print it or save it as a PDF.

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 WHERE country IN ('NL', 'BE', 'DE') do?

  1. ASorts rows in the order of the list
  2. BKeeps rows whose country value contains all three codes at once
  3. CKeeps rows whose country is not in the list
  4. DKeeps rows whose country equals any value in the list
2.Easy

Which aggregate function counts rows?

  1. ASUM
  2. BCOUNT
  3. CAVG
  4. DMAX
3.Easy

In a LIKE pattern, what does the _ (underscore) wildcard stand for?

  1. AExactly one character
  2. BA space character
  3. CAny letter but no digits
  4. DZero or more characters
4.Medium

Which statement about HAVING is correct?

  1. AIt cannot be used with GROUP BY
  2. BIt must come before WHERE in the SELECT statement
  3. CIt sorts the results
  4. DIt can use aggregate functions to filter groups
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?

  1. AJoin the employees table with itself using two aliases
  2. BCombine the table with itself using UNION ALL and a WHERE filter
  3. CCreate a second copy of the table on disk
  4. DUse GROUP BY manager_id only
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?

  1. A8
  2. B3
  3. C5
  4. D15
7.Hard

What does the following return: SELECT name FROM students WHERE grade > (SELECT AVG(grade) FROM students)?

  1. AStudents with a grade above the average grade
  2. BStudents with the highest grade only
  3. CThe average grade of all students
  4. DAn error because subqueries are not allowed in WHERE
8.Hard

What is a known drawback of decomposing tables into BCNF compared with 3NF?

  1. ABCNF allows more redundancy than 3NF
  2. BBCNF tables cannot have primary keys
  3. CThe decomposition always loses data when joined back
  4. DSome functional dependencies may no longer be checkable within a single table

Answer key

  1. 1. D · Keeps rows whose country equals any value in the list
  2. 2. B · COUNT
  3. 3. A · Exactly one character
  4. 4. D · It can use aggregate functions to filter groups
  5. 5. A · Join the employees table with itself using two aliases
  6. 6. C · 5
  7. 7. A · Students with a grade above the average grade
  8. 8. D · Some functional dependencies may no longer be checkable within a single table

Full step-by-step solutions: practise this topic on examproblems.com.