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 CROSS JOIN return?
- AThe rows of the first table only
- BOnly the rows that match on a shared key column
- COnly rows that do not match
- DEvery combination of rows from the two tables
2.Easy
A foreign key is:
- AA key used by foreign users
- BA column whose values must be unique across all rows of the table
- CA key that is always encrypted
- DA column that refers to the primary key of another table
3.Easy
Statements such as CREATE, ALTER and DROP belong to which part of SQL?
- AData Manipulation Language (DML)
- BTransaction Control Language (TCL)
- CData Control Language (DCL)
- DData Definition Language (DDL)
4.Medium
Students can take many courses and courses have many students. How is this modelled in tables?
- AWith a list of course ids stored in one column
- BWith a junction table holding foreign keys to both students and courses
- CBy merging students and courses into one table
- DWith a foreign key column course_id in the students table pointing to courses
5.Medium
A column holds the values 10, 20 and NULL. What does AVG(col) return?
- A15
- B10
- C30
- DNULL
6.Medium
In relational algebra, the projection operator (π) corresponds to:
- ACombining two tables on a key
- BChoosing which columns appear in the result
- CSorting the result
- DChoosing which rows satisfy a given condition
7.Hard
Table employee(emp_id, dept_id, dept_name) has the key emp_id, and dept_id → dept_name. Which statement is correct?
- AIt is not in 1NF
- BIt is not in 2NF
- CIt is in 2NF but not in 3NF
- DIt is in BCNF and therefore in 3NF
8.Hard
With multiversion concurrency control (MVCC), how can readers avoid blocking writers?
- AWriters are not allowed while any reader is active
- BReaders see a consistent snapshot of committed row versions while writers create new versions
- CReaders read uncommitted data directly
- DReaders always wait until all writers have committed