How do foreign keys enforce referential integrity?
This question tests your understanding of constraints that link tables. It evaluates knowledge of preventing orphan records and maintaining data consistency.
Why Interviewers Ask This
Data integrity is paramount in database systems. Interviewers ask this to ensure you understand how to prevent invalid data relationships. Foreign keys are the primary mechanism for enforcing that child records actually reference existing parent records.
How to Answer This Question
Define a foreign key as a column referencing a primary or unique key in another table. Explain that it prevents actions that would create orphan rows, such as deleting a parent record if children exist. Mention cascading options like ON DELETE CASCADE.
Key Points to Cover
- References primary key in parent table
- Prevents orphan records
- Enforces data consistency
Sample Answer
A foreign key is a column in a child table that references the primary key of a parent table. It enforces referential integrity by ensuring that any value in the foreign key column must exist in the parent table. This pr…
Common Mistakes to Avoid
- Thinking foreign keys are optional for integrity
- Not understanding cascading behaviors
- Confusing foreign keys with primary keys
Sound confident on this question in 5 minutes
Answer once and get a 30-second AI critique of your structure, content, and delivery. First attempt is free — no signup needed.