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

An INNER JOIN returns:

  1. AAll rows from the left table, with NULLs where there is no match
  2. BRows that do not match
  3. CAll rows from both tables
  4. DOnly rows with matching values in both tables
2.Easy

Which statement deletes a whole table, including its structure?

  1. ATRUNCATE ROWS
  2. BDROP TABLE
  3. CREMOVE TABLE
  4. DDELETE FROM
3.Easy

Which aggregate function counts rows?

  1. ASUM
  2. BAVG
  3. CCOUNT
  4. DMAX
4.Medium

A LEFT JOIN returns:

  1. AAll rows from the left table and matching rows from the right, with NULLs where there is no match
  2. BRows that match in neither table
  3. COnly matching rows from both tables
  4. DAll rows from the right table only
5.Medium

Students can take many courses and courses have many students. How is this modelled in tables?

  1. AWith a junction table holding foreign keys to both students and courses
  2. BWith a foreign key column course_id in the students table pointing to courses
  3. CBy merging students and courses into one table
  4. DWith a list of course ids stored in one column
6.Medium

Second normal form (2NF) removes:

  1. APartial dependencies of non-key columns on part of a composite key
  2. BForeign keys
  3. CAll NULL values
  4. DTransitive dependencies between non-key columns via another non-key column
7.Hard

With multiversion concurrency control (MVCC), how can readers avoid blocking writers?

  1. AWriters are not allowed while any reader is active
  2. BReaders see a consistent snapshot of committed row versions while writers create new versions
  3. CReaders read uncommitted data directly
  4. DReaders always wait until all writers have committed
8.Hard

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

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

Answer key

  1. 1. D · Only rows with matching values in both tables
  2. 2. B · DROP TABLE
  3. 3. C · COUNT
  4. 4. A · All rows from the left table and matching rows from the right, with NULLs where there is no match
  5. 5. A · With a junction table holding foreign keys to both students and courses
  6. 6. A · Partial dependencies of non-key columns on part of a composite key
  7. 7. B · Readers see a consistent snapshot of committed row versions while writers create new versions
  8. 8. C · {A, C}

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