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

How do you sort a result from the highest to the lowest salary?

  1. ASORT salary DOWN
  2. BGROUP BY salary DESC
  3. CORDER BY salary DESC
  4. DORDER BY salary ASC
2.Easy

Which aggregate function returns the average of a numeric column?

  1. AMEAN
  2. BSUM
  3. CMEDIAN
  4. DAVG
3.Easy

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

  1. ACONTAINS
  2. BMATCH
  3. CSIMILAR
  4. DLIKE
4.Medium

What does ROLLBACK TO SAVEPOINT s1 do?

  1. ADeletes the savepoint and all tables changed since then
  2. BUndoes the changes made after savepoint s1, keeping the transaction open
  3. CUndoes the whole transaction from the beginning
  4. DEnds the transaction and commits everything
5.Medium

What is SQL injection?

  1. AAn attack where user input changes the structure of a SQL query
  2. BA way to add indexes
  3. CA database backup technique
  4. DA technique for inserting many rows quickly with a single INSERT statement
6.Medium

Which ACID property guarantees that committed changes survive a system crash?

  1. AAtomicity
  2. BIsolation
  3. CDurability
  4. DConsistency
7.Hard

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

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

x is NULL and y = 1. What is the value of the condition (x > 5 OR y = 1)?

  1. AUNKNOWN
  2. BTRUE
  3. CFALSE
  4. DNULL, so the row is always rejected

Answer key

  1. 1. C · ORDER BY salary DESC
  2. 2. D · AVG
  3. 3. D · LIKE
  4. 4. B · Undoes the changes made after savepoint s1, keeping the transaction open
  5. 5. A · An attack where user input changes the structure of a SQL query
  6. 6. C · Durability
  7. 7. D · name is neither grouped nor aggregated, so it has no single value per group
  8. 8. B · TRUE

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