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 UNION do with the results of two SELECT queries?

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

Which statement adds a new column to an existing table?

  1. AUPDATE TABLE
  2. BALTER TABLE
  3. CINSERT COLUMN
  4. DCREATE COLUMN
3.Easy

What is a candidate key?

  1. AAny column that contains NULL values
  2. BA column that is waiting to become a foreign key
  3. CA set of columns shared between two tables to link their rows
  4. DA minimal set of columns that uniquely identifies each row
4.Medium

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

  1. ANULL
  2. BAn error
  3. CAn empty string
  4. D0
5.Medium

When is WHERE EXISTS (subquery) true for a row?

  1. AWhen the subquery returns at least one row
  2. BWhen the subquery returns no NULL values
  3. CWhen the subquery returns exactly one row
  4. DWhen the subquery returns a number greater than zero
6.Medium

What does the "A" in ACID stand for?

  1. AAccuracy
  2. BAggregation
  3. CAvailability
  4. DAtomicity
7.Hard

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

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

When is a schedule of concurrent transactions called serializable?

  1. AWhen no transaction ever reads data
  2. BWhen its effect is equivalent to some serial execution of the same transactions
  3. CWhen the transactions run on one CPU only
  4. DWhen every transaction is given a serial number

Answer key

  1. 1. A · Combines them into one result and removes duplicate rows
  2. 2. B · ALTER TABLE
  3. 3. D · A minimal set of columns that uniquely identifies each row
  4. 4. A · NULL
  5. 5. A · When the subquery returns at least one row
  6. 6. D · Atomicity
  7. 7. C · COUNT(*) counts the NULL-filled row as 1 for customers without orders
  8. 8. B · When its effect is equivalent to some serial execution of the same transactions

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