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 stored in a separate table
  4. DA key that is generated by the database
2.Easy

Which rows does WHERE price BETWEEN 10 AND 20 select?

  1. ARows with price outside the range 10 to 20
  2. BRows with price above 10 and below 20, excluding 10 and 20
  3. CRows with price equal to 10 or 20 only
  4. DRows with price from 10 to 20, including 10 and 20
3.Easy

Which statement adds a new column to an existing table?

  1. AUPDATE TABLE
  2. BINSERT COLUMN
  3. CCREATE COLUMN
  4. DALTER TABLE
4.Medium

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

  1. AAtomicity
  2. BIsolation
  3. CDurability
  4. DAvailability
5.Medium

A column holds the values 10, 20 and NULL. What does AVG(col) return?

  1. A15
  2. B10
  3. CNULL
  4. D30
6.Medium

Which query returns the number of different cities in the customers table?

  1. ASELECT COUNT(city) FROM customers GROUP BY city
  2. BSELECT COUNT(DISTINCT city) FROM customers
  3. CSELECT SUM(DISTINCT city) FROM customers
  4. DSELECT DISTINCT COUNT(city) FROM customers
7.Hard

Two-phase locking (2PL) ensures:

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

What is a phantom read?

  1. AA repeated query returns new rows inserted by another committed transaction
  2. BReading uncommitted changes
  3. CReading data that was never written
  4. DA query that returns no rows

Answer key

  1. 1. B · A key made up of two or more columns
  2. 2. D · Rows with price from 10 to 20, including 10 and 20
  3. 3. D · ALTER TABLE
  4. 4. B · Isolation
  5. 5. A · 15
  6. 6. B · SELECT COUNT(DISTINCT city) FROM customers
  7. 7. B · Conflict-serializable schedules
  8. 8. A · A repeated query returns new rows inserted by another committed transaction

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