Bird
0
0

Given entities Customer(cust_id, name), Order(order_id, date), and a one-to-one relationship where each order has exactly one customer, how should tables be designed?

hard📝 Application Q9 of 15
SQL - Table Relationships
Given entities Customer(cust_id, name), Order(order_id, date), and a one-to-one relationship where each order has exactly one customer, how should tables be designed?
AMerge Customer and Order into one table
BAdd cust_id as foreign key in Order table with UNIQUE constraint
CCreate separate table for the relationship
DAdd order_id as foreign key in Customer table without UNIQUE
Step-by-Step Solution
Solution:
  1. Step 1: Understand one-to-one relationship mapping

    One-to-one can be represented by placing foreign key with UNIQUE constraint in one table.
  2. Step 2: Choose correct foreign key placement

    Order table should have cust_id as foreign key with UNIQUE to ensure one-to-one mapping.
  3. Final Answer:

    Add cust_id as foreign key in Order table with UNIQUE constraint -> Option B
  4. Quick Check:

    One-to-one FK with UNIQUE = Add cust_id as foreign key in Order table with UNIQUE constraint [OK]
Quick Trick: One-to-one uses FK with UNIQUE constraint [OK]
Common Mistakes:
MISTAKES
  • Omitting UNIQUE constraint
  • Placing FK in wrong table
  • Creating unnecessary relationship table

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More SQL Quizzes