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

GRANT and REVOKE belong to which part of SQL?

  1. AData Query Language (DQL)
  2. BData Manipulation Language (DML)
  3. CData Control Language (DCL)
  4. DData Definition Language (DDL)
2.Easy

What does a UNIQUE constraint on a column guarantee?

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

A customer can place many orders, but each order belongs to exactly one customer. What type of relationship is this?

  1. AMany-to-many
  2. BZero-to-zero
  3. COne-to-one
  4. DOne-to-many
4.Medium

Second normal form (2NF) removes:

  1. AForeign keys
  2. BPartial dependencies of non-key columns on part of a composite key
  3. CTransitive dependencies between non-key columns via another non-key column
  4. DAll NULL values
5.Medium

Why can a table have only one clustered index?

  1. AClustered indexes can only be on the primary key
  2. BClustered indexes use too much memory
  3. CThe SQL standard forbids more than one index on a table
  4. DThe rows can be stored physically in only one order
6.Medium

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

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

Table enrolment(student_id, course_id, student_name, grade) has the key (student_id, course_id). Which normal form does it violate?

  1. ASecond normal form, because student_name depends on student_id only
  2. BNone, it is in BCNF
  3. CThird normal form only, because grade depends on student_name
  4. DFirst normal form, because the grade column does not hold atomic values
8.Hard

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

  1. AX contains NULL
  2. BY is a primary key
  3. CX is a superkey
  4. DY is atomic

Answer key

  1. 1. C · Data Control Language (DCL)
  2. 2. B · No two rows have the same non-NULL value in that column
  3. 3. D · One-to-many
  4. 4. B · Partial dependencies of non-key columns on part of a composite key
  5. 5. D · The rows can be stored physically in only one order
  6. 6. A · With a junction table holding foreign keys to both students and courses
  7. 7. A · Second normal form, because student_name depends on student_id only
  8. 8. C · X is a superkey

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