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 PostgreSQL and MySQL, which clause returns only the first 10 rows of a result?

  1. AFIRST 10 ONLY
  2. BMAX 10
  3. CLIMIT 10
  4. DTOP ROWS 10
2.Easy

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

  1. AAS
  2. BALIAS
  3. CRENAME
  4. DNAME
3.Easy

What does GROUP BY do in a query?

  1. APuts rows with the same values into groups so aggregates are computed per group
  2. BJoins two tables on their common columns
  3. CRemoves rows with NULL values
  4. DSorts the rows of the result alphabetically
4.Medium

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

  1. A4
  2. B3
  3. C7
  4. D12
5.Medium

Which statement about HAVING is correct?

  1. AIt can use aggregate functions to filter groups
  2. BIt must come before WHERE in the SELECT statement
  3. CIt sorts the results
  4. DIt cannot be used with GROUP BY
6.Medium

A view in SQL is:

  1. AAn index type
  2. BA stored query that behaves like a virtual table
  3. CA screen in the database client for browsing tables
  4. DA copy of a table on disk
7.Hard

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

  1. AA running total of amount ordered by day
  2. BThe total of all amounts on every row
  3. CThe average amount per day
  4. DOne row per day with that day's total only
8.Hard

What is a known drawback of decomposing tables into BCNF compared with 3NF?

  1. ABCNF tables cannot have primary keys
  2. BThe decomposition always loses data when joined back
  3. CBCNF allows more redundancy than 3NF
  4. DSome functional dependencies may no longer be checkable within a single table

Answer key

  1. 1. C · LIMIT 10
  2. 2. A · AS
  3. 3. A · Puts rows with the same values into groups so aggregates are computed per group
  4. 4. D · 12
  5. 5. A · It can use aggregate functions to filter groups
  6. 6. B · A stored query that behaves like a virtual table
  7. 7. A · A running total of amount ordered by day
  8. 8. D · Some functional dependencies may no longer be checkable within a single table

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