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. AVerifies the user's password
  2. BChecks whether a table exists before a query is run on it
  3. CCounts the rows in a table
  4. DRejects rows whose values do not satisfy a condition
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

What does NULL represent in SQL?

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

A table stores the customer's address on every order row. Changing the address in one row but not in the others is an example of:

  1. AA deletion anomaly
  2. BA phantom read
  3. CAn update anomaly
  4. DAn insertion anomaly
5.Medium

What is SQL injection?

  1. AA technique for inserting many rows quickly with a single INSERT statement
  2. BA database backup technique
  3. CA way to add indexes
  4. DAn attack where user input changes the structure of a SQL query
6.Medium

What does SELECT SUM(amount) FROM orders return when the WHERE clause matches no rows?

  1. AAn empty string
  2. B0
  3. CNULL
  4. DAn error
7.Hard

Boyce–Codd normal form (BCNF) requires that for every non-trivial functional dependency X → Y:

  1. AY is atomic
  2. BX contains NULL
  3. CY is a primary key
  4. DX is a superkey
8.Hard

What does EXPLAIN (or EXPLAIN ANALYZE in PostgreSQL) show for a query?

  1. AA rewrite of the query in relational algebra notation only
  2. BThe list of users who ran the query
  3. CThe execution plan chosen by the optimiser, such as scans and join methods
  4. DThe meaning of each SQL keyword in the query

Answer key

  1. 1. D · Rejects rows whose values do not satisfy a condition
  2. 2. D · Rows with price from 10 to 20, including 10 and 20
  3. 3. B · A missing or unknown value
  4. 4. C · An update anomaly
  5. 5. D · An attack where user input changes the structure of a SQL query
  6. 6. C · NULL
  7. 7. D · X is a superkey
  8. 8. C · The execution plan chosen by the optimiser, such as scans and join methods

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