0
0
SQLquery~5 mins

Referential integrity enforcement in SQL - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
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?
ALinks to a primary key in another table to enforce data consistency
BCreates a unique identifier for each row
CStores large text data
DIndexes the table for faster search
Which SQL clause enforces referential integrity when deleting a referenced row?
AON DELETE CASCADE
BGROUP BY
CORDER BY
DWHERE
If a foreign key constraint is violated, what will the database do?
ADelete all data in the table
BAutomatically fix the data
CIgnore the violation
DReject the operation to keep data consistent
What does ON DELETE SET NULL do?
APrevents deletion of the referenced row
BSets the foreign key to NULL when the referenced row is deleted
CDeletes the referencing row
DUpdates the foreign key to a default value
Which of these is NOT a benefit of enforcing referential integrity?
APreventing orphan records
BEnsuring data consistency
CAutomatically backing up data
DAvoiding broken links between tables
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.