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

GRANT and REVOKE belong to which part of SQL?

  1. AData Definition Language (DDL)
  2. BData Control Language (DCL)
  3. CData Manipulation Language (DML)
  4. DData Query Language (DQL)
2.Easy

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

  1. AOne-to-one
  2. BZero-to-zero
  3. CMany-to-many
  4. DOne-to-many
3.Easy

Which SQL statement changes values in rows that already exist?

  1. AINSERT
  2. BUPDATE
  3. CREPLACE COLUMN
  4. DMODIFY
4.Medium

What is a dirty read?

  1. AReading data from a corrupted disk
  2. BReading data without a WHERE clause
  3. CReading data written by another transaction that has not yet committed
  4. DReading the same row twice and getting the same value
5.Medium

What does SELECT COALESCE(phone, 'unknown') FROM customers return for a customer whose phone is NULL?

  1. AAn empty string
  2. B'unknown'
  3. CNULL
  4. DAn error
6.Medium

Which query returns the number of orders per customer?

  1. ASELECT customer_id, COUNT(*) FROM orders GROUP BY customer_id
  2. BSELECT customer_id FROM orders WHERE COUNT(*) > 0
  3. CSELECT DISTINCT COUNT(*) FROM orders
  4. DSELECT customer_id, COUNT(*) FROM orders ORDER BY customer_id
7.Hard

What is a phantom read?

  1. AA repeated query returns new rows inserted by another committed transaction
  2. BReading data that was never written
  3. CA query that returns no rows
  4. DReading uncommitted changes
8.Hard

What does the write-ahead logging (WAL) rule require?

  1. AEvery query must be logged before it is parsed
  2. BData pages must be written before the log
  3. CA change's log record must reach stable storage before the changed data page does
  4. DThe log is written only after a crash

Answer key

  1. 1. B · Data Control Language (DCL)
  2. 2. D · One-to-many
  3. 3. B · UPDATE
  4. 4. C · Reading data written by another transaction that has not yet committed
  5. 5. B · 'unknown'
  6. 6. A · SELECT customer_id, COUNT(*) FROM orders GROUP BY customer_id
  7. 7. A · A repeated query returns new rows inserted by another committed transaction
  8. 8. C · A change's log record must reach stable storage before the changed data page does

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