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 CROSS JOIN return?

  1. AOnly rows that do not match
  2. BEvery combination of rows from the two tables
  3. CThe rows of the first table only
  4. DOnly the rows that match on a shared key column
2.Easy

In the relational model, what is a row of a table called?

  1. AA tuple
  2. BAn attribute
  3. CA domain
  4. DA schema
3.Easy

GRANT and REVOKE belong to which part of SQL?

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

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

  1. AAn empty string
  2. BNULL
  3. CAn error
  4. D0
5.Medium

Why does SELECT price * 2 AS double_price FROM t WHERE double_price > 10 fail in most databases?

  1. AWHERE is evaluated before the SELECT list, so the alias does not exist yet
  2. BAliases may not contain an underscore
  3. CWHERE can only compare text columns
  4. DArithmetic is not allowed in the SELECT list
6.Medium

A LEFT JOIN returns:

  1. AAll rows from the right table only
  2. BOnly matching rows from both tables
  3. CRows that match in neither table
  4. DAll rows from the left table and matching rows from the right, with NULLs where there is no match
7.Hard

Why is SELECT dept, name, COUNT(*) FROM emp GROUP BY dept invalid in standard SQL?

  1. Adept must appear inside an aggregate function
  2. Bname is neither grouped nor aggregated, so it has no single value per group
  3. CGROUP BY must list all columns of the table
  4. DCOUNT(*) cannot be used together with GROUP BY
8.Hard

What does the following return: SELECT name FROM students WHERE grade > (SELECT AVG(grade) FROM students)?

  1. AStudents with the highest grade only
  2. BAn error because subqueries are not allowed in WHERE
  3. CThe average grade of all students
  4. DStudents with a grade above the average grade

Answer key

  1. 1. B · Every combination of rows from the two tables
  2. 2. A · A tuple
  3. 3. B · Data Control Language (DCL)
  4. 4. B · NULL
  5. 5. A · WHERE is evaluated before the SELECT list, so the alias does not exist yet
  6. 6. D · All rows from the left table and matching rows from the right, with NULLs where there is no match
  7. 7. B · name is neither grouped nor aggregated, so it has no single value per group
  8. 8. D · Students with a grade above the average grade

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