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 a CHECK constraint do?

  1. ARejects rows whose values do not satisfy a condition
  2. BChecks whether a table exists before a query is run on it
  3. CVerifies the user's password
  4. DCounts the rows in a table
2.Easy

Which keyword gives a column or table a temporary alternative name in a query?

  1. ANAME
  2. BALIAS
  3. CRENAME
  4. DAS
3.Easy

What does NULL represent in SQL?

  1. AA false Boolean
  2. BThe number zero in numeric columns
  3. CA missing or unknown value
  4. DAn empty string
4.Medium

When is WHERE EXISTS (subquery) true for a row?

  1. AWhen the subquery returns a number greater than zero
  2. BWhen the subquery returns no NULL values
  3. CWhen the subquery returns exactly one row
  4. DWhen the subquery returns at least one row
5.Medium

Table a has 3 rows and table b has 4 rows. How many rows does SELECT * FROM a CROSS JOIN b return?

  1. A12
  2. B4
  3. C3
  4. D7
6.Medium

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

  1. ANULL
  2. BAn empty string
  3. CAn error
  4. D'unknown'
7.Hard

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

  1. ADENSE_RANK()
  2. BROW_NUMBER()
  3. CCOUNT()
  4. DRANK()
8.Hard

R(A, B, C, D) has the functional dependencies A → B and C → D. What is the candidate key?

  1. A{A, C}
  2. B{A}
  3. C{B, D}
  4. D{C}

Answer key

  1. 1. A · Rejects rows whose values do not satisfy a condition
  2. 2. D · AS
  3. 3. C · A missing or unknown value
  4. 4. D · When the subquery returns at least one row
  5. 5. A · 12
  6. 6. D · 'unknown'
  7. 7. B · ROW_NUMBER()
  8. 8. A · {A, C}

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