You want to design a strict one-to-one relationship between tables Driver and License where each driver has exactly one license. Which design best enforces this?
hard📝 Application Q8 of 15
SQL - Table Relationships
You want to design a strict one-to-one relationship between tables Driver and License where each driver has exactly one license. Which design best enforces this?
AUse a composite primary key in <code>License</code> combining <code>LicenseID</code> and <code>DriverID</code>.
BAdd a foreign key <code>DriverID</code> in <code>License</code> without UNIQUE constraint.
CCreate a separate primary key in <code>License</code> and a foreign key <code>DriverID</code> without UNIQUE constraint.
DUse the same primary key <code>DriverID</code> in both tables, with <code>License.DriverID</code> as primary key and foreign key referencing <code>Driver(DriverID)</code>.
Step-by-Step Solution
Solution:
Step 1: Enforce one-to-one strictly
Using the same primary key value in both tables ensures exactly one matching row.
Step 2: Foreign key as primary key
Making License.DriverID both primary key and foreign key enforces uniqueness and referential integrity.
Final Answer:
Use the same primary key DriverID in both tables, with License.DriverID as primary key and foreign key referencing Driver(DriverID). is the best design for strict one-to-one.
Quick Check:
Same PK in both tables enforces strict one-to-one [OK]
Quick Trick:Use same PK in both tables for strict one-to-one [OK]
Common Mistakes:
MISTAKES
Not enforcing UNIQUE on foreign key
Using separate PK without uniqueness
Using composite keys unnecessarily
Master "Table Relationships" in SQL
9 interactive learning modes - each teaches the same concept differently