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

What does ROLLBACK do in a transaction?

  1. ASaves all changes of the transaction permanently to disk
  2. BDeletes the table
  3. CUndoes the changes made since the transaction began
  4. DRepeats the last statement
2.Easy

What is a primary key?

  1. AA column that may hold duplicate values but must never contain NULL
  2. BA password for the database
  3. CThe first column of every table
  4. DA column or set of columns that uniquely identifies each row
3.Easy

An INNER JOIN returns:

  1. AOnly rows with matching values in both tables
  2. BRows that do not match
  3. CAll rows from the left table, with NULLs where there is no match
  4. DAll rows from both tables
4.Medium

A view in SQL is:

  1. AA screen in the database client for browsing tables
  2. BAn index type
  3. CA copy of a table on disk
  4. DA stored query that behaves like a virtual table
5.Medium

Which ACID property guarantees that committed changes survive a system crash?

  1. AIsolation
  2. BConsistency
  3. CAtomicity
  4. DDurability
6.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
7.Hard

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

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

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

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

Answer key

  1. 1. C · Undoes the changes made since the transaction began
  2. 2. D · A column or set of columns that uniquely identifies each row
  3. 3. A · Only rows with matching values in both tables
  4. 4. D · A stored query that behaves like a virtual table
  5. 5. D · Durability
  6. 6. D · Join the employees table with itself using two aliases
  7. 7. A · X is a superkey
  8. 8. B · 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.