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 statement deletes a whole table, including its structure?

  1. ATRUNCATE ROWS
  2. BDELETE FROM
  3. CREMOVE TABLE
  4. DDROP TABLE
2.Easy

What does UNION do with the results of two SELECT queries?

  1. AKeeps only rows that appear in the first query but not the second
  2. BCombines them into one result and removes duplicate rows
  3. CJoins them side by side on a key
  4. DKeeps only rows that appear in both
3.Easy

Which statement adds a new column to an existing table?

  1. AALTER TABLE
  2. BINSERT COLUMN
  3. CUPDATE TABLE
  4. DCREATE COLUMN
4.Medium

In relational algebra, the projection operator (π) corresponds to:

  1. AChoosing which rows satisfy a given condition
  2. BCombining two tables on a key
  3. CSorting the result
  4. DChoosing which columns appear in the result
5.Medium

Why are indexes created on columns?

  1. ATo save disk space
  2. BTo prevent NULL values
  3. CTo make inserts and updates faster on those columns
  4. DTo speed up searches and joins on those columns
6.Medium

What does SELECT SUM(amount) FROM orders return when the WHERE clause matches no rows?

  1. ANULL
  2. B0
  3. CAn empty string
  4. DAn error
7.Hard

Why do many DBMSs use strict two-phase locking, holding exclusive locks until commit?

  1. AIt prevents cascading aborts, because nobody can read uncommitted writes
  2. BIt removes the need for a transaction log
  3. CIt allows transactions to read dirty data safely
  4. DIt makes deadlocks impossible
8.Hard

An app runs UPDATE item SET qty = 4, version = 8 WHERE id = 1 AND version = 7, and reports a conflict if no row was updated. What technique is this?

  1. ADatabase sharding
  2. BWrite-ahead logging
  3. COptimistic concurrency control
  4. DStrict two-phase locking with row locks

Answer key

  1. 1. D · DROP TABLE
  2. 2. B · Combines them into one result and removes duplicate rows
  3. 3. A · ALTER TABLE
  4. 4. D · Choosing which columns appear in the result
  5. 5. D · To speed up searches and joins on those columns
  6. 6. A · NULL
  7. 7. A · It prevents cascading aborts, because nobody can read uncommitted writes
  8. 8. C · Optimistic concurrency control

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