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

Which statement removes rows from a table?

  1. ATRUNCATE COLUMN
  2. BDELETE
  3. CREMOVE
  4. DDROP
2.Easy

What does NULL represent in SQL?

  1. AAn empty string
  2. BA false Boolean
  3. CThe number zero in numeric columns
  4. DA missing or unknown value
3.Easy

What does ROLLBACK do in a transaction?

  1. AUndoes the changes made since the transaction began
  2. BSaves all changes of the transaction permanently to disk
  3. CDeletes the table
  4. DRepeats the last statement
4.Medium

What does SELECT COALESCE(phone, 'unknown') FROM customers return for a customer whose phone is NULL?

  1. A'unknown'
  2. BAn empty string
  3. CAn error
  4. DNULL
5.Medium

A view in SQL is:

  1. AA stored query that behaves like a virtual table
  2. BAn index type
  3. CA copy of a table on disk
  4. DA screen in the database client for browsing tables
6.Medium

Why can a table have only one clustered index?

  1. AClustered indexes use too much memory
  2. BThe rows can be stored physically in only one order
  3. CThe SQL standard forbids more than one index on a table
  4. DClustered indexes can only be on the primary key
7.Hard

Two doctors on call each check that the other is still on call, then both sign off at the same time. Which anomaly can snapshot isolation still allow here?

  1. ADirty write
  2. BDirty read
  3. CWrite skew
  4. DNon-repeatable read within one transaction
8.Hard

What does the write-ahead logging (WAL) rule require?

  1. AA change's log record must reach stable storage before the changed data page does
  2. BEvery query must be logged before it is parsed
  3. CThe log is written only after a crash
  4. DData pages must be written before the log

Answer key

  1. 1. B · DELETE
  2. 2. D · A missing or unknown value
  3. 3. A · Undoes the changes made since the transaction began
  4. 4. A · 'unknown'
  5. 5. A · A stored query that behaves like a virtual table
  6. 6. B · The rows can be stored physically in only one order
  7. 7. C · Write skew
  8. 8. A · A change's log record must reach stable storage before the changed data page does

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