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 primary key?

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

What does GROUP BY do in a query?

  1. APuts rows with the same values into groups so aggregates are computed per group
  2. BRemoves rows with NULL values
  3. CSorts the rows of the result alphabetically
  4. DJoins two tables on their common columns
3.Easy

GRANT and REVOKE belong to which part of SQL?

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

A table has rows where col is NULL. Which rows does WHERE col = NULL return?

  1. AAn error in every database
  2. BAll rows of the table
  3. CNo rows, because the comparison is unknown
  4. DOnly the rows where col is NULL, as with IS NULL
5.Medium

A foreign key is declared with ON DELETE CASCADE. What happens when a parent row is deleted?

  1. AThe foreign key in the child rows is set to NULL automatically
  2. BThe delete is always rejected
  3. CThe child rows that reference it are deleted automatically
  4. DThe parent row is copied to an archive table
6.Medium

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

  1. AIsolation
  2. BAvailability
  3. CAtomicity
  4. DDurability
7.Hard

Two-phase locking (2PL) ensures:

  1. AConflict-serializable schedules
  2. BThat transactions never wait
  3. CThat no locks are needed
  4. DThat deadlocks can never happen
8.Hard

When is decomposing R into R1 and R2 guaranteed to be lossless?

  1. AWhen R1 and R2 have no attributes in common
  2. BWhen R1 and R2 have the same number of columns
  3. CWhen the common attributes of R1 and R2 form a superkey of R1 or of R2
  4. DWhen every attribute of R appears in both R1 and R2

Answer key

  1. 1. A · A column or set of columns that uniquely identifies each row
  2. 2. A · Puts rows with the same values into groups so aggregates are computed per group
  3. 3. A · Data Control Language (DCL)
  4. 4. C · No rows, because the comparison is unknown
  5. 5. C · The child rows that reference it are deleted automatically
  6. 6. A · Isolation
  7. 7. A · Conflict-serializable schedules
  8. 8. C · When the common attributes of R1 and R2 form a superkey of R1 or of R2

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