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 is a composite key?

  1. AA key that allows duplicate values
  2. BA key made up of two or more columns
  3. CA key that is generated by the database
  4. DA key stored in a separate table
2.Easy

What does ROLLBACK do in a transaction?

  1. ADeletes the table
  2. BSaves all changes of the transaction permanently to disk
  3. CRepeats the last statement
  4. DUndoes the changes made since the transaction began
3.Easy

What is an entity-relationship (ER) diagram used for?

  1. AModelling entities, their attributes and relationships when designing a database
  2. BShowing how a query is executed
  3. CMeasuring database performance
  4. DListing the users of a database
4.Medium

What does INTERSECT return when used between two SELECT queries?

  1. AAll rows from both results
  2. BRows in the first result but not the second
  3. CRows that appear in both results
  4. DThe Cartesian product of the results
5.Medium

What does the "A" in ACID stand for?

  1. AAtomicity
  2. BAggregation
  3. CAccuracy
  4. DAvailability
6.Medium

What does ROLLBACK TO SAVEPOINT s1 do?

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

Table b contains the values 1, 2 and NULL in column y. What does SELECT * FROM a WHERE x NOT IN (SELECT y FROM b) return?

  1. ANo rows at all
  2. BOnly rows of a where x is NULL
  3. CRows of a where x is not 1 or 2
  4. DEvery row of a
8.Hard

A correlated subquery is one that:

  1. AReferences columns of the outer query and is evaluated per outer row
  2. BJoins two tables with a foreign key
  3. CUses only aggregate functions
  4. DRuns only once before the outer query and caches its result for every row

Answer key

  1. 1. B · A key made up of two or more columns
  2. 2. D · Undoes the changes made since the transaction began
  3. 3. A · Modelling entities, their attributes and relationships when designing a database
  4. 4. C · Rows that appear in both results
  5. 5. A · Atomicity
  6. 6. A · Undoes the changes made after savepoint s1, keeping the transaction open
  7. 7. A · No rows at all
  8. 8. A · References columns of the outer query and is evaluated per outer row

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