Bird
0
0

What happens if you try to insert a record in a child table with a foreign key value that does not exist in the parent table?

easy📝 Conceptual Q1 of 15
SQL - Table Constraints
What happens if you try to insert a record in a child table with a foreign key value that does not exist in the parent table?
AThe insertion fails with a foreign key constraint error.
BThe record is inserted, and the foreign key is ignored.
CThe parent table automatically creates a matching record.
DThe database converts the foreign key to NULL.
Step-by-Step Solution
Solution:
  1. Step 1: Understand foreign key enforcement

    A foreign key ensures that the child table's value must exist in the parent table.
  2. Step 2: Check behavior on invalid insert

    Inserting a value not present in the parent table violates the foreign key constraint, causing an error.
  3. Final Answer:

    The insertion fails with a foreign key constraint error. -> Option A
  4. Quick Check:

    Foreign key violation = insertion error [OK]
Quick Trick: Foreign keys prevent invalid references, causing insert errors [OK]
Common Mistakes:
MISTAKES
  • Assuming foreign key allows any value
  • Thinking parent table auto-creates missing keys
  • Believing foreign key converts invalid values to NULL

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More SQL Quizzes