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 NULL represent in SQL?

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

What does COMMIT do in a transaction?

  1. ALocks the whole database
  2. BStarts a new table
  3. CMakes all changes of the transaction permanent
  4. DUndoes all changes made since the transaction began
3.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
4.Medium

What does EXCEPT (called MINUS in Oracle) return?

  1. ARows that appear in both queries
  2. BRows of the first query that do not appear in the second
  3. CAll rows from both queries without duplicates
  4. DRows of the second query that do not appear in the first one
5.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
6.Medium

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

  1. ACombining two tables on a key
  2. BChoosing which columns appear in the result
  3. CSorting the result
  4. DChoosing which rows satisfy a given condition
7.Hard

Which window function assigns 1, 2, 3, ... to rows within each partition without ties?

  1. ACOUNT()
  2. BROW_NUMBER()
  3. CRANK()
  4. DDENSE_RANK()
8.Hard

When is a schedule of concurrent transactions called serializable?

  1. AWhen the transactions run on one CPU only
  2. BWhen its effect is equivalent to some serial execution of the same transactions
  3. CWhen no transaction ever reads data
  4. DWhen every transaction is given a serial number

Answer key

  1. 1. A · A missing or unknown value
  2. 2. C · Makes all changes of the transaction permanent
  3. 3. B · A key made up of two or more columns
  4. 4. B · Rows of the first query that do not appear in the second
  5. 5. A · 'unknown'
  6. 6. B · Choosing which columns appear in the result
  7. 7. B · ROW_NUMBER()
  8. 8. B · When its effect is equivalent to some serial execution of the same transactions

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