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 keyword sorts the result of a query?

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

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

  1. AAny sequence of zero or more characters
  2. BExactly one character in that position of the string
  3. CAny single digit
  4. DThe end of the string
3.Easy

Statements such as CREATE, ALTER and DROP belong to which part of SQL?

  1. AData Manipulation Language (DML)
  2. BData Control Language (DCL)
  3. CData Definition Language (DDL)
  4. DTransaction Control Language (TCL)
4.Medium

Second normal form (2NF) removes:

  1. AForeign keys
  2. BAll NULL values
  3. CTransitive dependencies between non-key columns via another non-key column
  4. DPartial dependencies of non-key columns on part of a composite 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. AUse GROUP BY manager_id only
  2. BCombine the table with itself using UNION ALL and a WHERE filter
  3. CCreate a second copy of the table on disk
  4. DJoin the employees table with itself using two aliases
6.Medium

Why does SELECT price * 2 AS double_price FROM t WHERE double_price > 10 fail in most databases?

  1. AArithmetic is not allowed in the SELECT list
  2. BWHERE is evaluated before the SELECT list, so the alias does not exist yet
  3. CWHERE can only compare text columns
  4. DAliases may not contain an underscore
7.Hard

There is a composite index on (last_name, first_name). Which condition can use it most effectively?

  1. AWHERE first_name = 'Eva'
  2. BWHERE last_name = 'Jansen'
  3. CWHERE first_name LIKE '%a'
  4. DWHERE UPPER(first_name) = 'EVA'
8.Hard

What is a phantom read?

  1. AA query that returns no rows
  2. BA repeated query returns new rows inserted by another committed transaction
  3. CReading data that was never written
  4. DReading uncommitted changes

Answer key

  1. 1. A · ORDER BY
  2. 2. A · Any sequence of zero or more characters
  3. 3. C · Data Definition Language (DDL)
  4. 4. D · Partial dependencies of non-key columns on part of a composite key
  5. 5. D · Join the employees table with itself using two aliases
  6. 6. B · WHERE is evaluated before the SELECT list, so the alias does not exist yet
  7. 7. B · WHERE last_name = 'Jansen'
  8. 8. B · A repeated query returns new rows inserted by another committed transaction

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