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 constraint makes sure a column can never be left empty (NULL)?

  1. AUNIQUE
  2. BNOT NULL
  3. CCHECK NULL
  4. DDEFAULT
2.Easy

In a LIKE pattern, what does the _ (underscore) wildcard stand for?

  1. AA space character
  2. BZero or more characters
  3. CAny letter but no digits
  4. DExactly one character
3.Easy

Which SQL statement retrieves data from a table?

  1. ASELECT
  2. BUPDATE
  3. CINSERT
  4. DCREATE
4.Medium

Which ACID property means concurrent transactions do not see each other's unfinished changes?

  1. AAvailability
  2. BDurability
  3. CAtomicity
  4. DIsolation
5.Medium

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

  1. A0
  2. BAn error
  3. CAn empty string
  4. DNULL
6.Medium

Third normal form (3NF) removes:

  1. ATransitive dependencies between non-key attributes
  2. BComposite keys
  3. CAtomic values
  4. DRedundant indexes on columns that are not part of a key
7.Hard

What does EXPLAIN (or EXPLAIN ANALYZE in PostgreSQL) show for a query?

  1. AThe list of users who ran the query
  2. BThe execution plan chosen by the optimiser, such as scans and join methods
  3. CThe meaning of each SQL keyword in the query
  4. DA rewrite of the query in relational algebra notation only
8.Hard

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

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

Answer key

  1. 1. B · NOT NULL
  2. 2. D · Exactly one character
  3. 3. A · SELECT
  4. 4. D · Isolation
  5. 5. D · NULL
  6. 6. A · Transitive dependencies between non-key attributes
  7. 7. B · The execution plan chosen by the optimiser, such as scans and join methods
  8. 8. B · 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.