Bird
0
0

Consider this table design:

medium📝 Debug Q14 of 15
SQL - Table Relationships
Consider this table design:
CREATE TABLE Employee (
  EmployeeID INT PRIMARY KEY,
  Name VARCHAR(50)
);

CREATE TABLE EmployeeDetails (
  DetailID INT PRIMARY KEY,
  EmployeeID INT,
  Address VARCHAR(100),
  FOREIGN KEY (EmployeeID) REFERENCES Employee(EmployeeID)
);

What is missing to enforce a one-to-one relationship between Employee and EmployeeDetails?
AAdd PRIMARY KEY on EmployeeID in EmployeeDetails
BAdd NOT NULL constraint on EmployeeID in EmployeeDetails
CRemove FOREIGN KEY constraint
DAdd UNIQUE constraint on EmployeeID in EmployeeDetails
Step-by-Step Solution
Solution:
  1. Step 1: Identify current constraints

    EmployeeDetails has a foreign key to Employee but no uniqueness on EmployeeID, so multiple details can link to one employee.
  2. Step 2: Determine what enforces one-to-one

    Adding UNIQUE on EmployeeID ensures each employee links to at most one detail, enforcing one-to-one.
  3. Final Answer:

    Add UNIQUE constraint on EmployeeID in EmployeeDetails -> Option D
  4. Quick Check:

    Unique foreign key needed for one-to-one [OK]
Quick Trick: Add UNIQUE on foreign key column for one-to-one [OK]
Common Mistakes:
MISTAKES
  • Assuming NOT NULL enforces one-to-one
  • Removing foreign key breaks relationship
  • Confusing primary key with foreign key uniqueness

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More SQL Quizzes