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

  1. AAn artificial identifier with no business meaning, such as an auto-increment id
  2. BA key made from real-world data such as an email address
  3. CA key that is only used in views
  4. DA key that refers to another table
2.Easy

Which SQL statement changes values in rows that already exist?

  1. AINSERT
  2. BMODIFY
  3. CUPDATE
  4. DREPLACE COLUMN
3.Easy

What does GROUP BY do in a query?

  1. ASorts the rows of the result alphabetically
  2. BPuts rows with the same values into groups so aggregates are computed per group
  3. CJoins two tables on their common columns
  4. DRemoves rows with NULL values
4.Medium

What is SQL injection?

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

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

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

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

  1. ASorting the result
  2. BChoosing which columns appear in the result
  3. CChoosing which rows satisfy a given condition
  4. DCombining two tables on a key
7.Hard

When is decomposing R into R1 and R2 guaranteed to be lossless?

  1. AWhen every attribute of R appears in both R1 and R2
  2. BWhen the common attributes of R1 and R2 form a superkey of R1 or of R2
  3. CWhen R1 and R2 have no attributes in common
  4. DWhen R1 and R2 have the same number of columns
8.Hard

With multiversion concurrency control (MVCC), how can readers avoid blocking writers?

  1. AReaders see a consistent snapshot of committed row versions while writers create new versions
  2. BReaders always wait until all writers have committed
  3. CWriters are not allowed while any reader is active
  4. DReaders read uncommitted data directly

Answer key

  1. 1. A · An artificial identifier with no business meaning, such as an auto-increment id
  2. 2. C · UPDATE
  3. 3. B · Puts rows with the same values into groups so aggregates are computed per group
  4. 4. D · An attack where user input changes the structure of a SQL query
  5. 5. C · When the subquery returns at least one row
  6. 6. B · Choosing which columns appear in the result
  7. 7. B · When the common attributes of R1 and R2 form a superkey of R1 or of R2
  8. 8. A · Readers see a consistent snapshot of committed row versions while writers create new versions

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