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 UNION do with the results of two SELECT queries?

  1. AKeeps only rows that appear in both
  2. BJoins them side by side on a key
  3. CKeeps only rows that appear in the first query but not the second
  4. DCombines them into one result and removes duplicate rows
2.Easy

Which constraint makes sure a column can never be left empty (NULL)?

  1. ADEFAULT
  2. BUNIQUE
  3. CNOT NULL
  4. DCHECK NULL
3.Easy

Which SQL statement adds new rows to a table?

  1. AALTER
  2. BINSERT
  3. CSELECT
  4. DUPDATE
4.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. AA phantom read
  2. BAn update anomaly
  3. CA deletion anomaly
  4. DAn insertion anomaly
5.Medium

A column holds the values 10, 20 and NULL. What does AVG(col) return?

  1. A30
  2. B10
  3. C15
  4. DNULL
6.Medium

First normal form (1NF) requires that:

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

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

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

Why is NATURAL JOIN considered risky in production queries?

  1. AIt is not supported by any database
  2. BIt ignores primary and foreign keys and keeps only NULL rows
  3. CIt joins on every column with the same name, so a new column can silently change the result
  4. DIt always returns a Cartesian product

Answer key

  1. 1. D · Combines them into one result and removes duplicate rows
  2. 2. C · NOT NULL
  3. 3. B · INSERT
  4. 4. B · An update anomaly
  5. 5. C · 15
  6. 6. D · Each column contains atomic values and there are no repeating groups
  7. 7. D · When the common attributes of R1 and R2 form a superkey of R1 or of R2
  8. 8. C · It joins on every column with the same name, so a new column can silently change the result

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