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 a UNIQUE constraint on a column guarantee?

  1. AThe column automatically becomes the primary key of the table
  2. BThe column cannot be changed after insert
  3. CNo two rows have the same non-NULL value in that column
  4. DThe column values are sorted
2.Easy

Which statement adds a new column to an existing table?

  1. ACREATE COLUMN
  2. BUPDATE TABLE
  3. CALTER TABLE
  4. DINSERT COLUMN
3.Easy

What does NULL represent in SQL?

  1. AThe number zero in numeric columns
  2. BAn empty string
  3. CA missing or unknown value
  4. DA false Boolean
4.Medium

An employees table has a column manager_id that refers to another employee. How do you list each employee next to their manager's name?

  1. AUse GROUP BY manager_id only
  2. BCreate a second copy of the table on disk
  3. CCombine the table with itself using UNION ALL and a WHERE filter
  4. DJoin the employees table with itself using two aliases
5.Medium

What does ROLLBACK TO SAVEPOINT s1 do?

  1. AUndoes the changes made after savepoint s1, keeping the transaction open
  2. BDeletes the savepoint and all tables changed since then
  3. CUndoes the whole transaction from the beginning
  4. DEnds the transaction and commits everything
6.Medium

What is a database trigger?

  1. AA query that a user runs by hand
  2. BA type of index that speeds up searches
  3. CCode that runs automatically when a specified event such as INSERT, UPDATE or DELETE occurs on a table
  4. DA scheduled backup of the database
7.Hard

When is decomposing R into R1 and R2 guaranteed to be lossless?

  1. AWhen R1 and R2 have the same number of columns
  2. BWhen R1 and R2 have no attributes in common
  3. CWhen the common attributes of R1 and R2 form a superkey of R1 or of R2
  4. DWhen every attribute of R appears in both R1 and R2
8.Hard

Why is SELECT dept, name, COUNT(*) FROM emp GROUP BY dept invalid in standard SQL?

  1. AGROUP BY must list all columns of the table
  2. Bdept must appear inside an aggregate function
  3. CCOUNT(*) cannot be used together with GROUP BY
  4. Dname is neither grouped nor aggregated, so it has no single value per group

Answer key

  1. 1. C · No two rows have the same non-NULL value in that column
  2. 2. C · ALTER TABLE
  3. 3. C · A missing or unknown value
  4. 4. D · Join the employees table with itself using two aliases
  5. 5. A · Undoes the changes made after savepoint s1, keeping the transaction open
  6. 6. C · Code that runs automatically when a specified event such as INSERT, UPDATE or DELETE occurs on a table
  7. 7. C · When the common attributes of R1 and R2 form a superkey of R1 or of R2
  8. 8. D · name is neither grouped nor aggregated, so it has no single value per group

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