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 rows does WHERE price BETWEEN 10 AND 20 select?

  1. ARows with price outside the range 10 to 20
  2. BRows with price from 10 to 20, including 10 and 20
  3. CRows with price above 10 and below 20, excluding 10 and 20
  4. DRows with price equal to 10 or 20 only
2.Easy

What does GROUP BY do in a query?

  1. APuts rows with the same values into groups so aggregates are computed per group
  2. BSorts the rows of the result alphabetically
  3. CRemoves rows with NULL values
  4. DJoins two tables on their common columns
3.Easy

What does WHERE country IN ('NL', 'BE', 'DE') do?

  1. AKeeps rows whose country equals any value in the list
  2. BKeeps rows whose country is not in the list
  3. CSorts rows in the order of the list
  4. DKeeps rows whose country value contains all three codes at once
4.Medium

Which ACID property guarantees that committed changes survive a system crash?

  1. AIsolation
  2. BDurability
  3. CConsistency
  4. DAtomicity
5.Medium

A foreign key is declared with ON DELETE CASCADE. What happens when a parent row is deleted?

  1. AThe delete is always rejected
  2. BThe child rows that reference it are deleted automatically
  3. CThe parent row is copied to an archive table
  4. DThe foreign key in the child rows is set to NULL automatically
6.Medium

What is a database trigger?

  1. AA query that a user runs by hand
  2. BCode that runs automatically when a specified event such as INSERT, UPDATE or DELETE occurs on a table
  3. CA type of index that speeds up searches
  4. DA scheduled backup of the database
7.Hard

A reporting database copies customer names into the orders table to avoid joins. What is the main cost of this denormalisation?

  1. ARedundant copies must be kept consistent whenever customer data changes
  2. BThe database cannot use indexes any more
  3. CPrimary keys can no longer be used
  4. DQueries on the orders table become slower
8.Hard

Table employee(emp_id, dept_id, dept_name) has the key emp_id, and dept_id → dept_name. Which statement is correct?

  1. AIt is in BCNF and therefore in 3NF
  2. BIt is not in 1NF
  3. CIt is in 2NF but not in 3NF
  4. DIt is not in 2NF

Answer key

  1. 1. B · Rows with price from 10 to 20, including 10 and 20
  2. 2. A · Puts rows with the same values into groups so aggregates are computed per group
  3. 3. A · Keeps rows whose country equals any value in the list
  4. 4. B · Durability
  5. 5. B · The child rows that reference it are deleted automatically
  6. 6. B · Code that runs automatically when a specified event such as INSERT, UPDATE or DELETE occurs on a table
  7. 7. A · Redundant copies must be kept consistent whenever customer data changes
  8. 8. C · It is in 2NF but not in 3NF

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