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 aggregate function returns the average of a numeric column?

  1. AMEAN
  2. BAVG
  3. CMEDIAN
  4. DSUM
2.Easy

Which clause filters rows before grouping?

  1. AWHERE
  2. BHAVING
  3. CORDER BY
  4. DGROUP BY
3.Easy

Which keyword sorts the result of a query?

  1. AORDER BY
  2. BGROUP BY
  3. CSORT
  4. DARRANGE
4.Medium

First normal form (1NF) requires that:

  1. AThere are no foreign keys
  2. BEvery table has exactly one column
  3. CEach column contains atomic values and there are no repeating groups
  4. DEvery non-key column depends on the whole key and on nothing but the key
5.Medium

An employees table has a column manager_id that refers to another employee. How do you list each employee next to their manager's name?

  1. AJoin the employees table with itself using two aliases
  2. BCombine the table with itself using UNION ALL and a WHERE filter
  3. CCreate a second copy of the table on disk
  4. DUse GROUP BY manager_id only
6.Medium

What does ROLLBACK TO SAVEPOINT s1 do?

  1. AUndoes the changes made after savepoint s1, keeping the transaction open
  2. BEnds the transaction and commits everything
  3. CUndoes the whole transaction from the beginning
  4. DDeletes the savepoint and all tables changed since then
7.Hard

Why might a query with WHERE YEAR(order_date) = 2025 not use an index on order_date?

  1. AIndexes never work with dates
  2. BYEAR is not valid SQL
  3. CApplying a function to the column prevents a simple index range lookup
  4. DAn index on order_date is only used for ORDER BY clauses, never for WHERE
8.Hard

What is a covering index for a query?

  1. AAn index that contains all columns the query needs, so the table itself need not be read
  2. BAn index that is rebuilt every night
  3. CAn index on the primary key only
  4. DAn index that covers every column of every table

Answer key

  1. 1. B · AVG
  2. 2. A · WHERE
  3. 3. A · ORDER BY
  4. 4. C · Each column contains atomic values and there are no repeating groups
  5. 5. A · Join the employees table with itself using two aliases
  6. 6. A · Undoes the changes made after savepoint s1, keeping the transaction open
  7. 7. C · Applying a function to the column prevents a simple index range lookup
  8. 8. A · An index that contains all columns the query needs, so the table itself need not be read

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