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 keeps duplicate rows
  2. BUNION ALL removes duplicate rows
  3. CUNION ALL only works on one table
  4. DUNION ALL sorts the result
2.Easy

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

  1. AALIAS
  2. BRENAME
  3. CAS
  4. DNAME
3.Easy

How do you sort a result from the highest to the lowest salary?

  1. ASORT salary DOWN
  2. BORDER BY salary DESC
  3. CGROUP BY salary DESC
  4. DORDER BY salary ASC
4.Medium

What does EXCEPT (called MINUS in Oracle) return?

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

What does the functional dependency A → B mean?

  1. AA and B are both primary keys
  2. BEach value of A is associated with exactly one value of B
  3. CEach value of B is associated with exactly one value of A
  4. DA is a foreign key referencing B
6.Medium

First normal form (1NF) requires that:

  1. AEach column contains atomic values and there are no repeating groups
  2. BEvery table has exactly one column
  3. CThere are no foreign keys
  4. DEvery non-key column depends on the whole key and on nothing but the key
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. A0
  2. BNULL
  3. CAn error
  4. D10
8.Hard

x is NULL and y = 1. What is the value of the condition (x > 5 OR y = 1)?

  1. ATRUE
  2. BNULL, so the row is always rejected
  3. CFALSE
  4. DUNKNOWN

Answer key

  1. 1. A · UNION ALL keeps duplicate rows
  2. 2. C · AS
  3. 3. B · ORDER BY salary DESC
  4. 4. A · Rows of the first query that do not appear in the second
  5. 5. B · Each value of A is associated with exactly one value of B
  6. 6. A · Each column contains atomic values and there are no repeating groups
  7. 7. A · 0
  8. 8. A · TRUE

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