What is referential integrity, and how would you check for and repair violations during cleaning?

Quick Overview

Asks what referential integrity means between child and parent tables and how to find and fix orphan records while cleaning data. Tests anti-join detection in SQL and pandas, NULL handling, choosing a repair from business evidence, and preventing new violations.

What is referential integrity, and how would you check for and repair violations during cleaning?

Role: Data Scientist

Category: Data Manipulation (SQL/Python)

Difficulty: medium

Interview Round: Other

What is referential integrity, and how would you check for and repair violations during cleaning? ```hint Start from the join Think about which join returns child rows that have no partner on the parent side. Before fixing any of them, ask why the parent is missing, because the reason decides the repair. ``` ### What a Strong Answer Covers - A precise definition in terms of foreign keys and parent rows, including how NULL foreign keys are treated - A detection method that works on large tables, and the pitfalls that make it report wrong counts - Several repair options and the evidence that decides between them - Measuring and documenting the violations before changing data - How to stop new violations from appearing ### Follow-up Questions - Why can a `NOT IN` check report zero orphans when there are some? - How would you handle fact rows that arrive before their matching dimension rows? - When is it acceptable to drop orphan rows, and how would you show the effect on downstream metrics? - How do you check referential integrity between two systems where you cannot declare a foreign key?

Overview: Asks what referential integrity means between child and parent tables and how to find and fix orphan records while cleaning data. Tests anti-join detection in SQL and pandas, NULL handling, choosing a repair from business evidence, and preventing new violations.

PracHub logo
General
Nov 24, 2026
mediumData ScientistOtherData Manipulation (SQL/Python)
0
0

What is referential integrity, and how would you check for and repair violations during cleaning?

What a Strong Answer Covers Guidance

  • A precise definition in terms of foreign keys and parent rows, including how NULL foreign keys are treated
  • A detection method that works on large tables, and the pitfalls that make it report wrong counts
  • Several repair options and the evidence that decides between them
  • Measuring and documenting the violations before changing data
  • How to stop new violations from appearing

Follow-up Questions Guidance

  • Why can a NOT IN check report zero orphans when there are some?
  • How would you handle fact rows that arrive before their matching dimension rows?
  • When is it acceptable to drop orphan rows, and how would you show the effect on downstream metrics?
  • How do you check referential integrity between two systems where you cannot declare a foreign key?