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

What does a CHECK constraint do?

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

What is a candidate key?

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

Which keyword gives a column or table a temporary alternative name in a query?

  1. ARENAME
  2. BAS
  3. CALIAS
  4. DNAME
4.Medium

Second normal form (2NF) removes:

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

What does the "A" in ACID stand for?

  1. AAggregation
  2. BAccuracy
  3. CAvailability
  4. DAtomicity
6.Medium

What does SELECT name, CASE WHEN grade >= 5.5 THEN 'pass' ELSE 'fail' END FROM results return?

  1. AEach name with the label 'pass' or 'fail' depending on the grade
  2. BOnly the students who passed
  3. CAn error because CASE is not allowed in SELECT
  4. DThe number of students who passed and failed
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. ANone, it is in BCNF
  2. BFirst normal form, because the grade column does not hold atomic values
  3. CThird normal form only, because grade depends on student_name
  4. DSecond normal form, because student_name depends on student_id only
8.Hard

What is a covering index for a query?

  1. AAn index that contains all columns the query needs, so the table itself need not be read
  2. BAn index on the primary key only
  3. CAn index that is rebuilt every night
  4. DAn index that covers every column of every table

Answer key

  1. 1. B · Rejects rows whose values do not satisfy a condition
  2. 2. C · A minimal set of columns that uniquely identifies each row
  3. 3. B · AS
  4. 4. B · Partial dependencies of non-key columns on part of a composite key
  5. 5. D · Atomicity
  6. 6. A · Each name with the label 'pass' or 'fail' depending on the grade
  7. 7. D · Second normal form, because student_name depends on student_id only
  8. 8. A · An index that contains all columns the query needs, so the table itself need not be read

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