Recall & Review
beginner
What is referential integrity in a database?
Referential integrity means that relationships between tables stay correct. If one table points to another, the data must match so no broken links happen.
Click to reveal answer
beginner
How does a foreign key help enforce referential integrity?
A foreign key is a column that links to a primary key in another table. It makes sure you can only add values that exist in the linked table, preventing wrong or missing references.
Click to reveal answer
intermediate
What happens if you try to delete a row that other rows reference via a foreign key?
The database will block the delete unless you specify rules like CASCADE to delete related rows too, or SET NULL to clear the reference. This keeps data consistent.
Click to reveal answer
intermediate
Explain the difference between ON DELETE CASCADE and ON DELETE SET NULL.
ON DELETE CASCADE deletes all rows that reference the deleted row. ON DELETE SET NULL sets the foreign key to NULL instead, keeping the row but removing the link.
Click to reveal answer
beginner
Why is referential integrity important in real-life databases?
It prevents errors like orphan records or broken links, which can cause wrong reports or app crashes. It keeps data trustworthy and easy to manage.
Click to reveal answer
What does a foreign key in a table do?
✗ Incorrect
A foreign key links to a primary key in another table to keep data consistent and enforce referential integrity.
Which SQL clause enforces referential integrity when deleting a referenced row?
✗ Incorrect
ON DELETE CASCADE automatically deletes rows that reference the deleted row, maintaining referential integrity.
If a foreign key constraint is violated, what will the database do?
✗ Incorrect
The database rejects changes that break referential integrity to avoid inconsistent data.
What does ON DELETE SET NULL do?
✗ Incorrect
ON DELETE SET NULL clears the foreign key value instead of deleting the row, keeping the row but removing the link.
Which of these is NOT a benefit of enforcing referential integrity?
✗ Incorrect
Referential integrity does not handle backups; it ensures data consistency and valid links.
Describe what referential integrity means and how foreign keys help enforce it.
Think about how tables relate and how the database keeps those links correct.
You got /3 concepts.
Explain the difference between ON DELETE CASCADE and ON DELETE SET NULL in foreign key constraints.
Consider what happens to rows that reference a deleted row.
You got /3 concepts.