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

A foreign key is:

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

How do you sort a result from the highest to the lowest salary?

  1. AORDER BY salary DESC
  2. BORDER BY salary ASC
  3. CSORT salary DOWN
  4. DGROUP BY salary DESC
3.Easy

A customer can place many orders, but each order belongs to exactly one customer. What type of relationship is this?

  1. AMany-to-many
  2. BZero-to-zero
  3. COne-to-many
  4. DOne-to-one
4.Medium

A table has rows where col is NULL. Which rows does WHERE col = NULL return?

  1. AAll rows of the table
  2. BNo rows, because the comparison is unknown
  3. CAn error in every database
  4. DOnly the rows where col is NULL, as with IS NULL
5.Medium

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

  1. A4
  2. B7
  3. C3
  4. D12
6.Medium

What does INTERSECT return when used between two SELECT queries?

  1. ARows in the first result but not the second
  2. BThe Cartesian product of the results
  3. CRows that appear in both results
  4. DAll rows from both results
7.Hard

What is a phantom read?

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

R(A, B, C, D) has the functional dependencies A → B and C → D. What is the candidate key?

  1. A{C}
  2. B{B, D}
  3. C{A}
  4. D{A, C}

Answer key

  1. 1. A · A column that refers to the primary key of another table
  2. 2. A · ORDER BY salary DESC
  3. 3. C · One-to-many
  4. 4. B · No rows, because the comparison is unknown
  5. 5. D · 12
  6. 6. C · Rows that appear in both results
  7. 7. D · A repeated query returns new rows inserted by another committed transaction
  8. 8. D · {A, C}

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