Bird
0
0

Given entities Employee(emp_id, name) and Department(dept_id, dept_name) with a one-to-many relationship (one department has many employees), which table structure correctly represents this?

medium📝 query result Q4 of 15
SQL - Table Relationships
Given entities Employee(emp_id, name) and Department(dept_id, dept_name) with a one-to-many relationship (one department has many employees), which table structure correctly represents this?
AEmployee(emp_id, name), Department(dept_id, dept_name)
BEmployee(emp_id, name), Department(dept_id, dept_name, emp_id)
CEmployee(emp_id, name, dept_id), Department(dept_id, dept_name)
DEmployee(emp_id, name, dept_name), Department(dept_id, dept_name)
Step-by-Step Solution
Solution:
  1. Step 1: Understand one-to-many relationship mapping

    In one-to-many, the 'many' side table gets a foreign key referencing the 'one' side.
  2. Step 2: Identify correct foreign key placement

    Employee is 'many' side, so Employee table should have dept_id as foreign key; Department table does not need emp_id.
  3. Final Answer:

    Employee(emp_id, name, dept_id), Department(dept_id, dept_name) -> Option C
  4. Quick Check:

    One-to-many FK in 'many' table = Employee(emp_id, name, dept_id), Department(dept_id, dept_name) [OK]
Quick Trick: Foreign key goes in the 'many' side table [OK]
Common Mistakes:
MISTAKES
  • Placing foreign key in the 'one' side table
  • Omitting foreign key entirely
  • Adding unrelated columns as foreign keys

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More SQL Quizzes