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 is a candidate key?

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

Which SQL statement retrieves data from a table?

  1. AUPDATE
  2. BINSERT
  3. CCREATE
  4. DSELECT
3.Easy

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

  1. ARENAME
  2. BAS
  3. CNAME
  4. DALIAS
4.Medium

What does EXCEPT (called MINUS in Oracle) return?

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

In relational algebra, the selection operator (σ) corresponds to which SQL clause?

  1. AWHERE
  2. BORDER BY
  3. CGROUP BY
  4. DSELECT list
6.Medium

A view in SQL is:

  1. AA copy of a table on disk
  2. BAn index type
  3. CA screen in the database client for browsing tables
  4. DA stored query that behaves like a virtual table
7.Hard

Transaction T1 locks row A and waits for row B, while T2 locks row B and waits for row A. What does a typical DBMS do?

  1. ADetects the deadlock and aborts one transaction as the victim
  2. BMerges the two transactions into one
  3. CLets both transactions wait until one of them commits normally
  4. DCommits both transactions at once
8.Hard

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

  1. APhantom read
  2. BDirty read
  3. CLost update
  4. DDeletion anomaly

Answer key

  1. 1. A · A minimal set of columns that uniquely identifies each row
  2. 2. D · SELECT
  3. 3. B · AS
  4. 4. C · Rows of the first query that do not appear in the second
  5. 5. A · WHERE
  6. 6. D · A stored query that behaves like a virtual table
  7. 7. A · Detects the deadlock and aborts one transaction as the victim
  8. 8. C · Lost update

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