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. BUndoes the changes made since the transaction began
  3. CRepeats the last statement
  4. DDeletes the table
2.Easy

What does a CHECK constraint do?

  1. AChecks whether a table exists before a query is run on it
  2. BRejects rows whose values do not satisfy a condition
  3. CCounts the rows in a table
  4. DVerifies the user's password
3.Easy

What does UNION do with the results of two SELECT queries?

  1. AJoins them side by side on a key
  2. BKeeps only rows that appear in the first query but not the second
  3. CCombines them into one result and removes duplicate rows
  4. DKeeps only rows that appear in both
4.Medium

In relational algebra, the projection operator (π) corresponds to:

  1. ASorting the result
  2. BChoosing which rows satisfy a given condition
  3. CChoosing which columns appear in the result
  4. DCombining two tables on a key
5.Medium

Why are indexes created on columns?

  1. ATo prevent NULL values
  2. BTo speed up searches and joins on those columns
  3. CTo save disk space
  4. DTo make inserts and updates faster on those columns
6.Medium

What is a database trigger?

  1. AA scheduled backup of the database
  2. BA type of index that speeds up searches
  3. CA query that a user runs by hand
  4. DCode that runs automatically when a specified event such as INSERT, UPDATE or DELETE occurs on a table
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. AOnly rows of a where x is NULL
  2. BEvery row of a
  3. CNo rows at all
  4. DRows of a where x is not 1 or 2
8.Hard

Given the functional dependencies A → B, B → C and C → D on R(A, B, C, D), what is the closure A+?

  1. A{A, B}
  2. B{A, B, C}
  3. C{A}
  4. D{A, B, C, D}

Answer key

  1. 1. B · Undoes the changes made since the transaction began
  2. 2. B · Rejects rows whose values do not satisfy a condition
  3. 3. C · Combines them into one result and removes duplicate rows
  4. 4. C · Choosing which columns appear in the result
  5. 5. B · To speed up searches and joins on those columns
  6. 6. D · Code that runs automatically when a specified event such as INSERT, UPDATE or DELETE occurs on a table
  7. 7. C · No rows at all
  8. 8. D · {A, B, C, D}

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