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 WHERE country IN ('NL', 'BE', 'DE') do?

  1. AKeeps rows whose country is not in the list
  2. BKeeps rows whose country equals any value in the list
  3. CKeeps rows whose country value contains all three codes at once
  4. DSorts rows in the order of the list
2.Easy

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

  1. AORDER BY salary ASC
  2. BGROUP BY salary DESC
  3. CORDER BY salary DESC
  4. DSORT salary DOWN
3.Easy

GRANT and REVOKE belong to which part of SQL?

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

First normal form (1NF) requires that:

  1. AThere are no foreign keys
  2. BEach column contains atomic values and there are no repeating groups
  3. CEvery table has exactly one column
  4. DEvery non-key column depends on the whole key and on nothing but the key
5.Medium

What does GRANT SELECT ON employees TO alice do?

  1. AAllows the user alice to read the employees table
  2. BMakes alice the owner of the database
  3. CCopies the employees table to alice
  4. DAllows alice to update and delete rows in the employees table
6.Medium

Which statement removes all rows of a table, keeps its structure and cannot take a WHERE clause?

  1. ADROP TABLE
  2. BTRUNCATE TABLE
  3. CALTER TABLE
  4. DDELETE FROM with a WHERE clause
7.Hard

Two transactions both read stock = 10, each subtracts 1 and writes the result, giving 9 instead of 8. Which anomaly is this?

  1. ADirty read
  2. BLost update
  3. CPhantom read
  4. DDeletion anomaly
8.Hard

Which window function assigns 1, 2, 3, ... to rows within each partition without ties?

  1. ADENSE_RANK()
  2. BRANK()
  3. CCOUNT()
  4. DROW_NUMBER()

Answer key

  1. 1. B · Keeps rows whose country equals any value in the list
  2. 2. C · ORDER BY salary DESC
  3. 3. C · Data Control Language (DCL)
  4. 4. B · Each column contains atomic values and there are no repeating groups
  5. 5. A · Allows the user alice to read the employees table
  6. 6. B · TRUNCATE TABLE
  7. 7. B · Lost update
  8. 8. D · ROW_NUMBER()

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