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

In PostgreSQL and MySQL, which clause returns only the first 10 rows of a result?

  1. ALIMIT 10
  2. BFIRST 10 ONLY
  3. CTOP ROWS 10
  4. DMAX 10
2.Easy

Statements such as CREATE, ALTER and DROP belong to which part of SQL?

  1. AData Definition Language (DDL)
  2. BData Manipulation Language (DML)
  3. CTransaction Control Language (TCL)
  4. DData Control Language (DCL)
3.Easy

What is an entity-relationship (ER) diagram used for?

  1. AMeasuring database performance
  2. BShowing how a query is executed
  3. CListing the users of a database
  4. DModelling entities, their attributes and relationships when designing a database
4.Medium

What does the "A" in ACID stand for?

  1. AAtomicity
  2. BAccuracy
  3. CAggregation
  4. DAvailability
5.Medium

What does SELECT name, CASE WHEN grade >= 5.5 THEN 'pass' ELSE 'fail' END FROM results return?

  1. AOnly the students who passed
  2. BThe number of students who passed and failed
  3. CEach name with the label 'pass' or 'fail' depending on the grade
  4. DAn error because CASE is not allowed in SELECT
6.Medium

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

  1. ATRUNCATE TABLE
  2. BDROP TABLE
  3. CDELETE FROM with a WHERE clause
  4. DALTER TABLE
7.Hard

What does SELECT day, SUM(amount) OVER (ORDER BY day) FROM sales compute?

  1. AOne row per day with that day's total only
  2. BThe average amount per day
  3. CA running total of amount ordered by day
  4. DThe total of all amounts on every row
8.Hard

Why might a query with WHERE YEAR(order_date) = 2025 not use an index on order_date?

  1. AYEAR is not valid SQL
  2. BIndexes never work with dates
  3. CAn index on order_date is only used for ORDER BY clauses, never for WHERE
  4. DApplying a function to the column prevents a simple index range lookup

Answer key

  1. 1. A · LIMIT 10
  2. 2. A · Data Definition Language (DDL)
  3. 3. D · Modelling entities, their attributes and relationships when designing a database
  4. 4. A · Atomicity
  5. 5. C · Each name with the label 'pass' or 'fail' depending on the grade
  6. 6. A · TRUNCATE TABLE
  7. 7. C · A running total of amount ordered by day
  8. 8. D · Applying a function to the column prevents a simple index range lookup

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