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 candidate key?

  1. AA column that is waiting to become a foreign key
  2. BA set of columns shared between two tables to link their rows
  3. CA minimal set of columns that uniquely identifies each row
  4. DAny column that contains NULL values
2.Easy

GRANT and REVOKE belong to which part of SQL?

  1. AData Control Language (DCL)
  2. BData Query Language (DQL)
  3. CData Definition Language (DDL)
  4. DData Manipulation Language (DML)
3.Easy

What does WHERE country IN ('NL', 'BE', 'DE') do?

  1. AKeeps rows whose country value contains all three codes at once
  2. BSorts rows in the order of the list
  3. CKeeps rows whose country equals any value in the list
  4. DKeeps rows whose country is not in the list
4.Medium

In relational algebra, the selection operator (σ) corresponds to which SQL clause?

  1. ASELECT list
  2. BWHERE
  3. CORDER BY
  4. DGROUP BY
5.Medium

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

  1. AChoosing which rows satisfy a given condition
  2. BChoosing which columns appear in the result
  3. CSorting the result
  4. DCombining two tables on a key
6.Medium

What does EXCEPT (called MINUS in Oracle) return?

  1. AAll rows from both queries without duplicates
  2. BRows of the first query that do not appear in the second
  3. CRows of the second query that do not appear in the first one
  4. DRows that appear in both queries
7.Hard

What is a covering index for a query?

  1. AAn index on the primary key only
  2. BAn index that is rebuilt every night
  3. CAn index that covers every column of every table
  4. DAn index that contains all columns the query needs, so the table itself need not be read
8.Hard

x is NULL and y = 1. What is the value of the condition (x > 5 OR y = 1)?

  1. ANULL, so the row is always rejected
  2. BFALSE
  3. CTRUE
  4. DUNKNOWN

Answer key

  1. 1. C · A minimal set of columns that uniquely identifies each row
  2. 2. A · Data Control Language (DCL)
  3. 3. C · Keeps rows whose country equals any value in the list
  4. 4. B · WHERE
  5. 5. B · Choosing which columns appear in the result
  6. 6. B · Rows of the first query that do not appear in the second
  7. 7. D · An index that contains all columns the query needs, so the table itself need not be read
  8. 8. C · TRUE

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