Which scenario demonstrates a violation of referential integrity?
2025
Which scenario demonstrates a violation of referential integrity?
- A.
Having duplicate EmployeeID values in an Employees table
- B.
Setting Age = -5 in an Employees table
- C.
Inserting ProductID = 'P999' into an Orders table where 'P999' doesn't exist in Products
- D.
Storing a Name as NULL in a Customers table
Attempted by 165 students.
Show answer & explanation
Correct answer: C
Referential integrity is a database rule that ensures relationships between tables remain consistent. It dictates that a Foreign Key in one table must always point to a valid, existing Primary Key in another table.
Why Option C Violates This Rule
Imagine you have two tables:
Products (Parent Table): Contains your actual inventory (e.g., P101, P102).
Orders (Child Table): Contains sales transactions.
When you try to insert ProductID = 'P999' into the Orders table, the database immediately checks the Products table to verify if 'P999' exists.
The Conflict: Because 'P999' does not exist in the master product list, the database cannot link the order to a real item.
The Result: This creates an orphan record—a transaction pointing to a nonexistent ghost product.
To prevent this data corruption, referential integrity rules will automatically block the action and throw an error