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

In a LIKE pattern, what does the % wildcard stand for?

  1. AExactly one character in that position of the string
  2. BThe end of the string
  3. CAny sequence of zero or more characters
  4. DAny single digit
2.Easy

Which keyword sorts the result of a query?

  1. AORDER BY
  2. BGROUP BY
  3. CARRANGE
  4. DSORT
3.Easy

What does UNION do with the results of two SELECT queries?

  1. ACombines them into one result and removes duplicate rows
  2. BKeeps only rows that appear in both
  3. CJoins them side by side on a key
  4. DKeeps only rows that appear in the first query but not the second
4.Medium

Students can take many courses and courses have many students. How is this modelled in tables?

  1. AWith a foreign key column course_id in the students table pointing to courses
  2. BWith a list of course ids stored in one column
  3. CBy merging students and courses into one table
  4. DWith a junction table holding foreign keys to both students and courses
5.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. AAn insertion anomaly
  2. BA phantom read
  3. CAn update anomaly
  4. DA deletion anomaly
6.Medium

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

  1. AGROUP BY
  2. BSELECT list
  3. CORDER BY
  4. DWHERE
7.Hard

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

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

What does SELECT day, SUM(amount) OVER (ORDER BY day) FROM sales compute?

  1. AThe total of all amounts on every row
  2. BThe average amount per day
  3. COne row per day with that day's total only
  4. DA running total of amount ordered by day

Answer key

  1. 1. C · Any sequence of zero or more characters
  2. 2. A · ORDER BY
  3. 3. A · Combines them into one result and removes duplicate rows
  4. 4. D · With a junction table holding foreign keys to both students and courses
  5. 5. C · An update anomaly
  6. 6. D · WHERE
  7. 7. D · When the common attributes of R1 and R2 form a superkey of R1 or of R2
  8. 8. D · A running total of amount ordered by day

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