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 operator is used for simple text pattern matching in a WHERE clause?

  1. AMATCH
  2. BSIMILAR
  3. CLIKE
  4. DCONTAINS
2.Easy

Which statement adds a new column to an existing table?

  1. AINSERT COLUMN
  2. BUPDATE TABLE
  3. CALTER TABLE
  4. DCREATE COLUMN
3.Easy

Which keyword sorts the result of a query?

  1. AORDER BY
  2. BARRANGE
  3. CGROUP BY
  4. DSORT
4.Medium

Why does SELECT price * 2 AS double_price FROM t WHERE double_price > 10 fail in most databases?

  1. AArithmetic is not allowed in the SELECT list
  2. BAliases may not contain an underscore
  3. CWHERE can only compare text columns
  4. DWHERE is evaluated before the SELECT list, so the alias does not exist yet
5.Medium

What does SELECT SUM(amount) FROM orders return when the WHERE clause matches no rows?

  1. AAn empty string
  2. BNULL
  3. C0
  4. DAn error
6.Medium

Third normal form (3NF) removes:

  1. AAtomic values
  2. BRedundant indexes on columns that are not part of a key
  3. CComposite keys
  4. DTransitive dependencies between non-key attributes
7.Hard

What does a FULL OUTER JOIN return?

  1. AThe Cartesian product, pairing each row of one table with every row of the other
  2. BAll rows from both tables, matched where possible and NULL-filled otherwise
  3. COnly unmatched rows
  4. DOnly matching rows
8.Hard

Why is NATURAL JOIN considered risky in production queries?

  1. AIt is not supported by any database
  2. BIt joins on every column with the same name, so a new column can silently change the result
  3. CIt ignores primary and foreign keys and keeps only NULL rows
  4. DIt always returns a Cartesian product

Answer key

  1. 1. C · LIKE
  2. 2. C · ALTER TABLE
  3. 3. A · ORDER BY
  4. 4. D · WHERE is evaluated before the SELECT list, so the alias does not exist yet
  5. 5. B · NULL
  6. 6. D · Transitive dependencies between non-key attributes
  7. 7. B · All rows from both tables, matched where possible and NULL-filled otherwise
  8. 8. B · It joins on every column with the same name, so a new column can silently change the result

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