Bird
0
0

You want to create a foreign key from Orders to Customers but allow Orders without a customer (optional link). Which is the best approach?

hard📝 Application Q9 of 15
SQL - Table Relationships
You want to create a foreign key from Orders to Customers but allow Orders without a customer (optional link). Which is the best approach?
AAdd a primary key constraint on the foreign key column.
BMake the foreign key column NOT NULL and add the foreign key constraint.
CDo not add a foreign key constraint and allow any values.
DMake the foreign key column nullable and add the foreign key constraint.
Step-by-Step Solution
Solution:
  1. Step 1: Understand optional foreign key relationships

    To allow missing links, the foreign key column must accept NULL values.
  2. Step 2: Choose correct constraint setup

    Making the column nullable and adding the foreign key constraint enforces links when present but allows NULLs.
  3. Final Answer:

    Make the foreign key column nullable and add the foreign key constraint. -> Option D
  4. Quick Check:

    Nullable foreign key allows optional links [OK]
Quick Trick: Nullable foreign key column allows optional references [OK]
Common Mistakes:
MISTAKES
  • Making foreign key NOT NULL blocks optional links
  • Skipping foreign key constraint loses referential integrity
  • Confusing primary key with foreign key

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More SQL Quizzes