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 gives a column or table a temporary alternative name in a query?

  1. ANAME
  2. BAS
  3. CRENAME
  4. DALIAS
2.Easy

Which SQL statement changes values in rows that already exist?

  1. AINSERT
  2. BUPDATE
  3. CMODIFY
  4. DREPLACE COLUMN
3.Easy

What does a CROSS JOIN return?

  1. AThe rows of the first table only
  2. BEvery combination of rows from the two tables
  3. COnly the rows that match on a shared key column
  4. DOnly rows that do not match
4.Medium

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

  1. AAliases may not contain an underscore
  2. BArithmetic is not allowed in the SELECT list
  3. CWHERE is evaluated before the SELECT list, so the alias does not exist yet
  4. DWHERE can only compare text columns
5.Medium

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

  1. AIsolation
  2. BAtomicity
  3. CDurability
  4. DAvailability
6.Medium

What does ROLLBACK TO SAVEPOINT s1 do?

  1. AUndoes the whole transaction from the beginning
  2. BEnds the transaction and commits everything
  3. CUndoes the changes made after savepoint s1, keeping the transaction open
  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. AAn index on order_date is only used for ORDER BY clauses, never for WHERE
  2. BIndexes never work with dates
  3. CYEAR is not valid SQL
  4. DApplying a function to the column prevents a simple index range lookup
8.Hard

Boyce–Codd normal form (BCNF) requires that for every non-trivial functional dependency X → Y:

  1. AX contains NULL
  2. BY is a primary key
  3. CY is atomic
  4. DX is a superkey

Answer key

  1. 1. B · AS
  2. 2. B · UPDATE
  3. 3. B · Every combination of rows from the two tables
  4. 4. C · WHERE is evaluated before the SELECT list, so the alias does not exist yet
  5. 5. A · Isolation
  6. 6. C · Undoes the changes made after savepoint s1, keeping the transaction open
  7. 7. D · Applying a function to the column prevents a simple index range lookup
  8. 8. D · X is a superkey

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