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 operator is used for simple text pattern matching in a WHERE clause?

  1. ALIKE
  2. BCONTAINS
  3. CMATCH
  4. DSIMILAR
2.Easy

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

  1. AORDER BY salary DESC
  2. BGROUP BY salary DESC
  3. CSORT salary DOWN
  4. DORDER BY salary ASC
3.Easy

What is a composite key?

  1. AA key made up of two or more columns
  2. BA key stored in a separate table
  3. CA key that is generated by the database
  4. DA key that allows duplicate values
4.Medium

Which query returns the number of different cities in the customers table?

  1. ASELECT COUNT(city) FROM customers GROUP BY city
  2. BSELECT SUM(DISTINCT city) FROM customers
  3. CSELECT DISTINCT COUNT(city) FROM customers
  4. DSELECT COUNT(DISTINCT city) FROM customers
5.Medium

What is a database trigger?

  1. ACode that runs automatically when a specified event such as INSERT, UPDATE or DELETE occurs on a table
  2. BA scheduled backup of the database
  3. CA type of index that speeds up searches
  4. DA query that a user runs by hand
6.Medium

Table a has 3 rows and table b has 4 rows. How many rows does SELECT * FROM a CROSS JOIN b return?

  1. A4
  2. B12
  3. C3
  4. D7
7.Hard

What does the write-ahead logging (WAL) rule require?

  1. AThe log is written only after a crash
  2. BEvery query must be logged before it is parsed
  3. CData pages must be written before the log
  4. DA change's log record must reach stable storage before the changed data page does
8.Hard

What does EXPLAIN (or EXPLAIN ANALYZE in PostgreSQL) show for a query?

  1. AThe list of users who ran the query
  2. BThe execution plan chosen by the optimiser, such as scans and join methods
  3. CA rewrite of the query in relational algebra notation only
  4. DThe meaning of each SQL keyword in the query

Answer key

  1. 1. A · LIKE
  2. 2. A · ORDER BY salary DESC
  3. 3. A · A key made up of two or more columns
  4. 4. D · SELECT COUNT(DISTINCT city) FROM customers
  5. 5. A · Code that runs automatically when a specified event such as INSERT, UPDATE or DELETE occurs on a table
  6. 6. B · 12
  7. 7. D · A change's log record must reach stable storage before the changed data page does
  8. 8. B · The execution plan chosen by the optimiser, such as scans and join methods

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