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 clause filters rows before grouping?

  1. AGROUP BY
  2. BHAVING
  3. CORDER BY
  4. DWHERE
2.Easy

A foreign key is:

  1. AA key that is always encrypted
  2. BA column that refers to the primary key of another table
  3. CA key used by foreign users
  4. DA column whose values must be unique across all rows of the table
3.Easy

What is a surrogate key?

  1. AA key that is only used in views
  2. BA key made from real-world data such as an email address
  3. CA key that refers to another table
  4. DAn artificial identifier with no business meaning, such as an auto-increment id
4.Medium

In relational algebra, the selection operator (σ) corresponds to which SQL clause?

  1. AGROUP BY
  2. BWHERE
  3. CORDER BY
  4. DSELECT list
5.Medium

What does a common table expression (WITH name AS (...)) provide?

  1. AA permanent table that stays stored on disk until it is dropped
  2. BAn index on a column
  3. CA new database user
  4. DA named temporary result that can be used within one statement
6.Medium

Third normal form (3NF) removes:

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

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

  1. AThe decomposition always loses data when joined back
  2. BSome functional dependencies may no longer be checkable within a single table
  3. CBCNF tables cannot have primary keys
  4. DBCNF allows more redundancy than 3NF
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. Astatus is a reserved word
  2. BThe WHERE condition on o rejects the NULL-filled rows, turning it into an inner join
  3. CThe join should use USING instead of ON
  4. DLEFT JOIN never keeps unmatched rows

Answer key

  1. 1. D · WHERE
  2. 2. B · A column that refers to the primary key of another table
  3. 3. D · An artificial identifier with no business meaning, such as an auto-increment id
  4. 4. B · WHERE
  5. 5. D · A named temporary result that can be used within one statement
  6. 6. B · Transitive dependencies between non-key attributes
  7. 7. B · Some functional dependencies may no longer be checkable within a single table
  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.