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 retrieves data from a table?

  1. ACREATE
  2. BINSERT
  3. CSELECT
  4. DUPDATE
2.Easy

Which statement deletes a whole table, including its structure?

  1. ATRUNCATE ROWS
  2. BDELETE FROM
  3. CREMOVE TABLE
  4. DDROP TABLE
3.Easy

What does NULL represent in SQL?

  1. AThe number zero in numeric columns
  2. BA missing or unknown value
  3. CA false Boolean
  4. DAn empty string
4.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
5.Medium

The orders table has 5 rows, each referring to an existing customer. The customers table has 3 rows. How many rows does an INNER JOIN on customer_id return?

  1. A8
  2. B3
  3. C5
  4. D15
6.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. AAn update anomaly
  2. BA deletion anomaly
  3. CA phantom read
  4. DAn insertion anomaly
7.Hard

Two-phase locking (2PL) ensures:

  1. AConflict-serializable schedules
  2. BThat deadlocks can never happen
  3. CThat no locks are needed
  4. DThat transactions never wait
8.Hard

What does the following return: SELECT name FROM students WHERE grade > (SELECT AVG(grade) FROM students)?

  1. AAn error because subqueries are not allowed in WHERE
  2. BThe average grade of all students
  3. CStudents with a grade above the average grade
  4. DStudents with the highest grade only

Answer key

  1. 1. C · SELECT
  2. 2. D · DROP TABLE
  3. 3. B · A missing or unknown value
  4. 4. C · Allows the user alice to read the employees table
  5. 5. C · 5
  6. 6. A · An update anomaly
  7. 7. A · Conflict-serializable schedules
  8. 8. C · Students with a grade above the average grade

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