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 surrogate key?

  1. AA key that refers to another table
  2. BA key made from real-world data such as an email address
  3. CAn artificial identifier with no business meaning, such as an auto-increment id
  4. DA key that is only used in views
2.Easy

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

  1. AAS
  2. BRENAME
  3. CNAME
  4. DALIAS
3.Easy

Which statement adds a new column to an existing table?

  1. ACREATE COLUMN
  2. BALTER TABLE
  3. CUPDATE TABLE
  4. DINSERT COLUMN
4.Medium

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

  1. AALTER TABLE
  2. BTRUNCATE TABLE
  3. CDROP TABLE
  4. DDELETE FROM with a WHERE clause
5.Medium

In relational algebra, the projection operator (π) corresponds to:

  1. ACombining two tables on a key
  2. BSorting the result
  3. CChoosing which columns appear in the result
  4. DChoosing which rows satisfy a given condition
6.Medium

A view in SQL is:

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

Two-phase locking (2PL) ensures:

  1. AThat transactions never wait
  2. BThat deadlocks can never happen
  3. CThat no locks are needed
  4. DConflict-serializable schedules
8.Hard

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

  1. ARANK()
  2. BCOUNT()
  3. CDENSE_RANK()
  4. DROW_NUMBER()

Answer key

  1. 1. C · An artificial identifier with no business meaning, such as an auto-increment id
  2. 2. A · AS
  3. 3. B · ALTER TABLE
  4. 4. B · TRUNCATE TABLE
  5. 5. C · Choosing which columns appear in the result
  6. 6. B · A stored query that behaves like a virtual table
  7. 7. D · Conflict-serializable schedules
  8. 8. D · ROW_NUMBER()

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