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

Which SQL keyword removes duplicate rows from a result?

  1. ASINGLE
  2. BDISTINCT
  3. CDIFFERENT
  4. DUNIQUE
2.Easy

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

  1. AA space character
  2. BAny letter but no digits
  3. CZero or more characters
  4. DExactly one character
3.Easy

In a LIKE pattern, what does the % wildcard stand for?

  1. AExactly one character in that position of the string
  2. BThe end of the string
  3. CAny single digit
  4. DAny sequence of zero or more characters
4.Medium

When is WHERE EXISTS (subquery) true for a row?

  1. AWhen the subquery returns a number greater than zero
  2. BWhen the subquery returns exactly one row
  3. CWhen the subquery returns no NULL values
  4. DWhen the subquery returns at least one row
5.Medium

A view in SQL is:

  1. AA screen in the database client for browsing tables
  2. BA copy of a table on disk
  3. CA stored query that behaves like a virtual table
  4. DAn index type
6.Medium

Table a has 3 rows and table b has 4 rows. How many rows does SELECT * FROM a CROSS JOIN b return?

  1. A3
  2. B7
  3. C4
  4. D12
7.Hard

What is a phantom read?

  1. AReading uncommitted changes
  2. BA repeated query returns new rows inserted by another committed transaction
  3. CReading data that was never written
  4. DA query that returns no rows
8.Hard

The query FROM customers c LEFT JOIN orders o ON o.customer_id = c.id WHERE o.status = 'paid' unexpectedly drops customers with no orders. Why?

  1. AThe join should use USING instead of ON
  2. BThe WHERE condition on o rejects the NULL-filled rows, turning it into an inner join
  3. CLEFT JOIN never keeps unmatched rows
  4. Dstatus is a reserved word

Answer key

  1. 1. B · DISTINCT
  2. 2. D · Exactly one character
  3. 3. D · Any sequence of zero or more characters
  4. 4. D · When the subquery returns at least one row
  5. 5. C · A stored query that behaves like a virtual table
  6. 6. D · 12
  7. 7. B · A repeated query returns new rows inserted by another committed transaction
  8. 8. B · The WHERE condition on o rejects the NULL-filled rows, turning it into an inner join

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