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

Which SQL statement changes values in rows that already exist?

  1. AREPLACE COLUMN
  2. BUPDATE
  3. CINSERT
  4. DMODIFY
2.Easy

Which keyword sorts the result of a query?

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

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

  1. AA tuple
  2. BA schema
  3. CAn attribute
  4. DA domain
4.Medium

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

  1. A10
  2. B30
  3. CNULL
  4. D15
5.Medium

What does GRANT SELECT ON employees TO alice do?

  1. AMakes alice the owner of the database
  2. BAllows alice to update and delete rows in the employees table
  3. CAllows the user alice to read the employees table
  4. DCopies the employees table to alice
6.Medium

First normal form (1NF) requires that:

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

A table has a million rows and a Boolean column is_active that is TRUE for 95% of them. Why might the optimiser ignore an index on is_active for WHERE is_active = TRUE?

  1. ATRUE is treated as NULL by the index
  2. BIndexes cannot be created on Boolean columns
  3. CThe optimiser never uses indexes in WHERE clauses
  4. DMost rows match, so a full table scan is cheaper than many index lookups
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. CSome functional dependencies may no longer be checkable within a single table
  4. DBCNF allows more redundancy than 3NF

Answer key

  1. 1. B · UPDATE
  2. 2. B · ORDER BY
  3. 3. A · A tuple
  4. 4. D · 15
  5. 5. C · Allows the user alice to read the employees table
  6. 6. C · Each column contains atomic values and there are no repeating groups
  7. 7. D · Most rows match, so a full table scan is cheaper than many index lookups
  8. 8. C · Some functional dependencies may no longer be checkable within a single table

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