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

A foreign key is:

  1. AA column that refers to the primary key of another table
  2. BA key used by foreign users
  3. CA key that is always encrypted
  4. DA column whose values must be unique across all rows of the table
2.Easy

An INNER JOIN returns:

  1. ARows that do not match
  2. BAll rows from the left table, with NULLs where there is no match
  3. COnly rows with matching values in both tables
  4. DAll rows from both tables
3.Easy

What does UNION do with the results of two SELECT queries?

  1. AKeeps only rows that appear in the first query but not the second
  2. BCombines them into one result and removes duplicate rows
  3. CKeeps only rows that appear in both
  4. DJoins them side by side on a key
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

What is a database trigger?

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

Students can take many courses and courses have many students. How is this modelled in tables?

  1. AWith a foreign key column course_id in the students table pointing to courses
  2. BBy merging students and courses into one table
  3. CWith a list of course ids stored in one column
  4. DWith a junction table holding foreign keys to both students and courses
7.Hard

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

  1. AStudents with a grade above the average grade
  2. BStudents with the highest grade only
  3. CAn error because subqueries are not allowed in WHERE
  4. DThe average grade of all students
8.Hard

Boyce–Codd normal form (BCNF) requires that for every non-trivial functional dependency X → Y:

  1. AY is atomic
  2. BX contains NULL
  3. CX is a superkey
  4. DY is a primary key

Answer key

  1. 1. A · A column that refers to the primary key of another table
  2. 2. C · Only rows with matching values in both tables
  3. 3. B · Combines them into one result and removes duplicate rows
  4. 4. A · Allows the user alice to read the employees table
  5. 5. D · Code that runs automatically when a specified event such as INSERT, UPDATE or DELETE occurs on a table
  6. 6. D · With a junction table holding foreign keys to both students and courses
  7. 7. A · Students with a grade above the average grade
  8. 8. C · X is a superkey

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