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

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

  1. AAny letter but no digits
  2. BZero or more characters
  3. CExactly one character
  4. DA space character
2.Easy

In PostgreSQL and MySQL, which clause returns only the first 10 rows of a result?

  1. ATOP ROWS 10
  2. BMAX 10
  3. CFIRST 10 ONLY
  4. DLIMIT 10
3.Easy

Which aggregate function counts rows?

  1. AAVG
  2. BMAX
  3. CSUM
  4. DCOUNT
4.Medium

In relational algebra, the projection operator (π) corresponds to:

  1. ASorting the result
  2. BCombining two tables on a key
  3. CChoosing which columns appear in the result
  4. DChoosing which rows satisfy a given condition
5.Medium

Which statement about HAVING is correct?

  1. AIt sorts the results
  2. BIt cannot be used with GROUP BY
  3. CIt can use aggregate functions to filter groups
  4. DIt must come before WHERE in the SELECT statement
6.Medium

A column holds the values 10, 20 and NULL. What does AVG(col) return?

  1. A10
  2. B30
  3. C15
  4. DNULL
7.Hard

What is the result of SELECT COUNT(col) FROM t if all values in col are NULL and the table has 10 rows?

  1. ANULL
  2. B0
  3. CAn error
  4. D10
8.Hard

Why do many DBMSs use strict two-phase locking, holding exclusive locks until commit?

  1. AIt makes deadlocks impossible
  2. BIt prevents cascading aborts, because nobody can read uncommitted writes
  3. CIt allows transactions to read dirty data safely
  4. DIt removes the need for a transaction log

Answer key

  1. 1. C · Exactly one character
  2. 2. D · LIMIT 10
  3. 3. D · COUNT
  4. 4. C · Choosing which columns appear in the result
  5. 5. C · It can use aggregate functions to filter groups
  6. 6. C · 15
  7. 7. B · 0
  8. 8. B · It prevents cascading aborts, because nobody can read uncommitted writes

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