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

How does UNION ALL differ from UNION?

  1. AUNION ALL removes duplicate rows
  2. BUNION ALL sorts the result
  3. CUNION ALL keeps duplicate rows
  4. DUNION ALL only works on one table
2.Easy

What is a candidate key?

  1. AA set of columns shared between two tables to link their rows
  2. BA column that is waiting to become a foreign key
  3. CA minimal set of columns that uniquely identifies each row
  4. DAny column that contains NULL values
3.Easy

What does a UNIQUE constraint on a column guarantee?

  1. AThe column automatically becomes the primary key of the table
  2. BThe column cannot be changed after insert
  3. CNo two rows have the same non-NULL value in that column
  4. DThe column values are sorted
4.Medium

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

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

What does EXCEPT (called MINUS in Oracle) return?

  1. AAll rows from both queries without duplicates
  2. BRows of the second query that do not appear in the first one
  3. CRows of the first query that do not appear in the second
  4. DRows that appear in both queries
6.Medium

Which ACID property guarantees that committed changes survive a system crash?

  1. AConsistency
  2. BIsolation
  3. CDurability
  4. DAtomicity
7.Hard

What is the result of SELECT COUNT(col) FROM t if all values in col are NULL and the table has 10 rows?

  1. ANULL
  2. B10
  3. CAn error
  4. D0
8.Hard

There is a composite index on (last_name, first_name). Which condition can use it most effectively?

  1. AWHERE last_name = 'Jansen'
  2. BWHERE first_name = 'Eva'
  3. CWHERE UPPER(first_name) = 'EVA'
  4. DWHERE first_name LIKE '%a'

Answer key

  1. 1. C · UNION ALL keeps duplicate rows
  2. 2. C · A minimal set of columns that uniquely identifies each row
  3. 3. C · No two rows have the same non-NULL value in that column
  4. 4. D · With a junction table holding foreign keys to both students and courses
  5. 5. C · Rows of the first query that do not appear in the second
  6. 6. C · Durability
  7. 7. D · 0
  8. 8. A · WHERE last_name = 'Jansen'

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