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 COMMIT do in a transaction?

  1. AStarts a new table
  2. BUndoes all changes made since the transaction began
  3. CMakes all changes of the transaction permanent
  4. DLocks the whole database
2.Easy

Which operator is used for simple text pattern matching in a WHERE clause?

  1. ALIKE
  2. BCONTAINS
  3. CSIMILAR
  4. DMATCH
3.Easy

Which aggregate function returns the average of a numeric column?

  1. ASUM
  2. BMEAN
  3. CAVG
  4. DMEDIAN
4.Medium

First normal form (1NF) requires that:

  1. AEvery non-key column depends on the whole key and on nothing but the key
  2. BEach column contains atomic values and there are no repeating groups
  3. CThere are no foreign keys
  4. DEvery table has exactly one column
5.Medium

A view in SQL is:

  1. AA screen in the database client for browsing tables
  2. BA copy of a table on disk
  3. CA stored query that behaves like a virtual table
  4. DAn index type
6.Medium

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

  1. AGROUP BY
  2. BORDER BY
  3. CSELECT list
  4. DWHERE
7.Hard

Given the functional dependencies A → B, B → C and C → D on R(A, B, C, D), what is the closure A+?

  1. A{A, B}
  2. B{A, B, C}
  3. C{A}
  4. D{A, B, C, D}
8.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. BGROUP BY must list all columns of the table
  3. Cname is neither grouped nor aggregated, so it has no single value per group
  4. DCOUNT(*) cannot be used together with GROUP BY

Answer key

  1. 1. C · Makes all changes of the transaction permanent
  2. 2. A · LIKE
  3. 3. C · AVG
  4. 4. B · Each column contains atomic values and there are no repeating groups
  5. 5. C · A stored query that behaves like a virtual table
  6. 6. D · WHERE
  7. 7. D · {A, B, C, D}
  8. 8. C · name is neither grouped nor aggregated, so it has no single value per group

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