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

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

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

What is a surrogate key?

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

Which SQL statement adds new rows to a table?

  1. AINSERT
  2. BALTER
  3. CUPDATE
  4. DSELECT
4.Medium

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

  1. AORDER BY
  2. BSELECT list
  3. CWHERE
  4. DGROUP BY
5.Medium

What does the functional dependency A → B mean?

  1. AEach value of A is associated with exactly one value of B
  2. BA and B are both primary keys
  3. CEach value of B is associated with exactly one value of A
  4. DA is a foreign key referencing B
6.Medium

What does GRANT SELECT ON employees TO alice do?

  1. AAllows the user alice to read the employees table
  2. BAllows alice to update and delete rows in the employees table
  3. CMakes alice the owner of the database
  4. DCopies the employees table to alice
7.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 2NF but not in 3NF
  2. BIt is not in 2NF
  3. CIt is not in 1NF
  4. DIt is in BCNF and therefore in 3NF
8.Hard

After customers LEFT JOIN orders, why use COUNT(o.id) rather than COUNT(*) to count orders per customer?

  1. ACOUNT(o.id) counts only distinct customers
  2. BCOUNT(*) counts the NULL-filled row as 1 for customers without orders
  3. CCOUNT(*) is not allowed after a join
  4. DCOUNT(*) ignores rows with NULL values

Answer key

  1. 1. B · Keeps rows whose country equals any value in the list
  2. 2. A · An artificial identifier with no business meaning, such as an auto-increment id
  3. 3. A · INSERT
  4. 4. C · WHERE
  5. 5. A · Each value of A is associated with exactly one value of B
  6. 6. A · Allows the user alice to read the employees table
  7. 7. A · It is in 2NF but not in 3NF
  8. 8. B · COUNT(*) counts the NULL-filled row as 1 for customers without orders

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