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

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

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

What does a CHECK constraint do?

  1. AVerifies the user's password
  2. BRejects rows whose values do not satisfy a condition
  3. CChecks whether a table exists before a query is run on it
  4. DCounts the rows in a table
3.Easy

In a LIKE pattern, what does the _ (underscore) wildcard stand for?

  1. AA space character
  2. BZero or more characters
  3. CAny letter but no digits
  4. DExactly one character
4.Medium

What does GRANT SELECT ON employees TO alice do?

  1. AAllows the user alice to read the employees table
  2. BCopies the employees table to alice
  3. CMakes alice the owner of the database
  4. DAllows alice to update and delete rows in the employees table
5.Medium

Why are indexes created on columns?

  1. ATo save disk space
  2. BTo prevent NULL values
  3. CTo make inserts and updates faster on those columns
  4. DTo speed up searches and joins on those columns
6.Medium

What does a common table expression (WITH name AS (...)) provide?

  1. AA new database user
  2. BA named temporary result that can be used within one statement
  3. CA permanent table that stays stored on disk until it is dropped
  4. DAn index on a column
7.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 the highest grade only
  4. DStudents with a grade above the average grade
8.Hard

Why do many DBMSs use strict two-phase locking, holding exclusive locks until commit?

  1. AIt prevents cascading aborts, because nobody can read uncommitted writes
  2. BIt makes deadlocks impossible
  3. CIt removes the need for a transaction log
  4. DIt allows transactions to read dirty data safely

Answer key

  1. 1. A · Data Definition Language (DDL)
  2. 2. B · Rejects rows whose values do not satisfy a condition
  3. 3. D · Exactly one character
  4. 4. A · Allows the user alice to read the employees table
  5. 5. D · To speed up searches and joins on those columns
  6. 6. B · A named temporary result that can be used within one statement
  7. 7. D · Students with a grade above the average grade
  8. 8. A · It prevents cascading aborts, because nobody can read uncommitted writes

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