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

Which SQL statement retrieves data from a table?

  1. AUPDATE
  2. BINSERT
  3. CSELECT
  4. DCREATE
2.Easy

Which SQL statement adds new rows to a table?

  1. AUPDATE
  2. BSELECT
  3. CALTER
  4. DINSERT
3.Easy

What is a candidate key?

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

What does the "A" in ACID stand for?

  1. AAggregation
  2. BAvailability
  3. CAccuracy
  4. DAtomicity
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

Why can a table have only one clustered index?

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

What does SELECT name, dept, AVG(salary) OVER (PARTITION BY dept) FROM emp return?

  1. AOne row per department with its average salary
  2. BAn error because name is not in a GROUP BY
  3. COnly employees who earn more than their department average
  4. DEvery employee row together with the average salary of their department
8.Hard

What does a FULL OUTER JOIN return?

  1. AOnly matching rows
  2. BOnly unmatched rows
  3. CThe Cartesian product, pairing each row of one table with every row of the other
  4. DAll rows from both tables, matched where possible and NULL-filled otherwise

Answer key

  1. 1. C · SELECT
  2. 2. D · INSERT
  3. 3. B · A minimal set of columns that uniquely identifies each row
  4. 4. D · Atomicity
  5. 5. D · To speed up searches and joins on those columns
  6. 6. D · The rows can be stored physically in only one order
  7. 7. D · Every employee row together with the average salary of their department
  8. 8. D · All rows from both tables, matched where possible and NULL-filled otherwise

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