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 statement removes rows from a table?

  1. ADROP
  2. BDELETE
  3. CTRUNCATE COLUMN
  4. DREMOVE
2.Easy

Which SQL statement retrieves data from a table?

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

In a LIKE pattern, what does the % wildcard stand for?

  1. AThe end of the string
  2. BAny sequence of zero or more characters
  3. CExactly one character in that position of the string
  4. DAny single digit
4.Medium

What does GRANT SELECT ON employees TO alice do?

  1. AMakes alice the owner of the database
  2. BCopies the employees table to alice
  3. CAllows alice to update and delete rows in the employees table
  4. DAllows the user alice to read the employees table
5.Medium

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

  1. ADROP TABLE
  2. BALTER TABLE
  3. CTRUNCATE TABLE
  4. DDELETE FROM with a WHERE clause
6.Medium

A view in SQL is:

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

What does SELECT day, SUM(amount) OVER (ORDER BY day) FROM sales compute?

  1. AA running total of amount ordered by day
  2. BOne row per day with that day's total only
  3. CThe average amount per day
  4. DThe total of all amounts on every row
8.Hard

After customers LEFT JOIN orders, why use COUNT(o.id) rather than COUNT(*) to count orders per customer?

  1. ACOUNT(o.id) counts only distinct customers
  2. BCOUNT(*) ignores rows with NULL values
  3. CCOUNT(*) counts the NULL-filled row as 1 for customers without orders
  4. DCOUNT(*) is not allowed after a join

Answer key

  1. 1. B · DELETE
  2. 2. C · SELECT
  3. 3. B · Any sequence of zero or more characters
  4. 4. D · Allows the user alice to read the employees table
  5. 5. C · TRUNCATE TABLE
  6. 6. B · A stored query that behaves like a virtual table
  7. 7. A · A running total of amount ordered by day
  8. 8. C · COUNT(*) counts the NULL-filled row as 1 for customers without orders

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