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

In a LIKE pattern, what does the % wildcard stand for?

  1. AExactly one character in that position of the string
  2. BAny single digit
  3. CThe end of the string
  4. DAny sequence of zero or more characters
2.Easy

Which aggregate function returns the average of a numeric column?

  1. AAVG
  2. BMEDIAN
  3. CSUM
  4. DMEAN
3.Easy

How does UNION ALL differ from UNION?

  1. AUNION ALL removes duplicate rows
  2. BUNION ALL sorts the result
  3. CUNION ALL only works on one table
  4. DUNION ALL keeps duplicate rows
4.Medium

A column holds the values 10, 20 and NULL. What does AVG(col) return?

  1. A10
  2. BNULL
  3. C15
  4. D30
5.Medium

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

  1. AWHERE
  2. BGROUP BY
  3. CSELECT list
  4. DORDER BY
6.Medium

Third normal form (3NF) removes:

  1. AAtomic values
  2. BRedundant indexes on columns that are not part of a key
  3. CTransitive dependencies between non-key attributes
  4. DComposite keys
7.Hard

Transaction T1 locks row A and waits for row B, while T2 locks row B and waits for row A. What does a typical DBMS do?

  1. AMerges the two transactions into one
  2. BLets both transactions wait until one of them commits normally
  3. CDetects the deadlock and aborts one transaction as the victim
  4. DCommits both transactions at once
8.Hard

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

  1. AThe log is written only after a crash
  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. DEvery query must be logged before it is parsed

Answer key

  1. 1. D · Any sequence of zero or more characters
  2. 2. A · AVG
  3. 3. D · UNION ALL keeps duplicate rows
  4. 4. C · 15
  5. 5. A · WHERE
  6. 6. C · Transitive dependencies between non-key attributes
  7. 7. C · Detects the deadlock and aborts one transaction as the victim
  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.