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 GROUP BY do in a query?

  1. ARemoves rows with NULL values
  2. BPuts rows with the same values into groups so aggregates are computed per group
  3. CSorts the rows of the result alphabetically
  4. DJoins two tables on their common columns
2.Easy

Which aggregate function returns the average of a numeric column?

  1. AMEDIAN
  2. BAVG
  3. CMEAN
  4. DSUM
3.Easy

Which keyword sorts the result of a query?

  1. AARRANGE
  2. BORDER BY
  3. CGROUP BY
  4. DSORT
4.Medium

Second normal form (2NF) removes:

  1. APartial dependencies of non-key columns on part of a composite key
  2. BAll NULL values
  3. CTransitive dependencies between non-key columns via another non-key column
  4. DForeign keys
5.Medium

What does EXCEPT (called MINUS in Oracle) return?

  1. ARows that appear in both queries
  2. BRows of the first query that do not appear in the second
  3. CRows of the second query that do not appear in the first one
  4. DAll rows from both queries without duplicates
6.Medium

Which statement removes all rows of a table, keeps its structure and cannot take a WHERE clause?

  1. ADROP TABLE
  2. BALTER TABLE
  3. CTRUNCATE TABLE
  4. DDELETE FROM with a WHERE clause
7.Hard

What is the result of SELECT COUNT(col) FROM t if all values in col are NULL and the table has 10 rows?

  1. AAn error
  2. B0
  3. C10
  4. DNULL
8.Hard

When is a schedule of concurrent transactions called serializable?

  1. AWhen every transaction is given a serial number
  2. BWhen no transaction ever reads data
  3. CWhen its effect is equivalent to some serial execution of the same transactions
  4. DWhen the transactions run on one CPU only

Answer key

  1. 1. B · Puts rows with the same values into groups so aggregates are computed per group
  2. 2. B · AVG
  3. 3. B · ORDER BY
  4. 4. A · Partial dependencies of non-key columns on part of a composite key
  5. 5. B · Rows of the first query that do not appear in the second
  6. 6. C · TRUNCATE TABLE
  7. 7. B · 0
  8. 8. C · When its effect is equivalent to some serial execution of the same transactions

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