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 is generated by the database
  2. BA key made up of two or more columns
  3. CA key stored in a separate table
  4. DA key that allows duplicate values
2.Easy

Which SQL keyword removes duplicate rows from a result?

  1. AUNIQUE
  2. BDISTINCT
  3. CSINGLE
  4. DDIFFERENT
3.Easy

Which SQL statement changes values in rows that already exist?

  1. AINSERT
  2. BUPDATE
  3. CMODIFY
  4. DREPLACE COLUMN
4.Medium

Third normal form (3NF) removes:

  1. ARedundant indexes on columns that are not part of a key
  2. BTransitive dependencies between non-key attributes
  3. CComposite keys
  4. DAtomic values
5.Medium

What is a dirty read?

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

Second normal form (2NF) removes:

  1. AForeign keys
  2. BTransitive dependencies between non-key columns via another non-key column
  3. CAll NULL values
  4. DPartial dependencies of non-key columns on part of a composite key
7.Hard

A table has a million rows and a Boolean column is_active that is TRUE for 95% of them. Why might the optimiser ignore an index on is_active for WHERE is_active = TRUE?

  1. ATRUE is treated as NULL by the index
  2. BMost rows match, so a full table scan is cheaper than many index lookups
  3. CIndexes cannot be created on Boolean columns
  4. DThe optimiser never uses indexes in WHERE clauses
8.Hard

Two transactions both read stock = 10, each subtracts 1 and writes the result, giving 9 instead of 8. Which anomaly is this?

  1. APhantom read
  2. BDirty read
  3. CLost update
  4. DDeletion anomaly

Answer key

  1. 1. B · A key made up of two or more columns
  2. 2. B · DISTINCT
  3. 3. B · UPDATE
  4. 4. B · Transitive dependencies between non-key attributes
  5. 5. A · Reading data written by another transaction that has not yet committed
  6. 6. D · Partial dependencies of non-key columns on part of a composite key
  7. 7. B · Most rows match, so a full table scan is cheaper than many index lookups
  8. 8. C · Lost update

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