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

GRANT and REVOKE belong to which part of SQL?

  1. AData Manipulation Language (DML)
  2. BData Definition Language (DDL)
  3. CData Control Language (DCL)
  4. DData Query Language (DQL)
2.Easy

Which statement deletes a whole table, including its structure?

  1. AREMOVE TABLE
  2. BTRUNCATE ROWS
  3. CDELETE FROM
  4. DDROP TABLE
3.Easy

Which rows does WHERE price BETWEEN 10 AND 20 select?

  1. ARows with price equal to 10 or 20 only
  2. BRows with price outside the range 10 to 20
  3. CRows with price from 10 to 20, including 10 and 20
  4. DRows with price above 10 and below 20, excluding 10 and 20
4.Medium

Which statement about HAVING is correct?

  1. AIt must come before WHERE in the SELECT statement
  2. BIt cannot be used with GROUP BY
  3. CIt sorts the results
  4. DIt can use aggregate functions to filter groups
5.Medium

What does ROLLBACK TO SAVEPOINT s1 do?

  1. AUndoes the changes made after savepoint s1, keeping the transaction open
  2. BDeletes the savepoint and all tables changed since then
  3. CEnds the transaction and commits everything
  4. DUndoes the whole transaction from the beginning
6.Medium

What is a dirty read?

  1. AReading the same row twice and getting the same value
  2. BReading data without a WHERE clause
  3. CReading data from a corrupted disk
  4. DReading data written by another transaction that has not yet committed
7.Hard

What is a phantom read?

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

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

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

Answer key

  1. 1. C · Data Control Language (DCL)
  2. 2. D · DROP TABLE
  3. 3. C · Rows with price from 10 to 20, including 10 and 20
  4. 4. D · It can use aggregate functions to filter groups
  5. 5. A · Undoes the changes made after savepoint s1, keeping the transaction open
  6. 6. D · Reading data written by another transaction that has not yet committed
  7. 7. A · A repeated query returns new rows inserted by another committed transaction
  8. 8. A · 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.