Bird
0
0

Consider an ER diagram with entities Employee(emp_id, name), Project(proj_id, title), and a many-to-many relationship WorksOn between them. How should you map this relationship into tables?

hard📝 Application Q15 of 15
SQL - Table Relationships
Consider an ER diagram with entities Employee(emp_id, name), Project(proj_id, title), and a many-to-many relationship WorksOn between them. How should you map this relationship into tables?
AAdd proj_id as a foreign key column in Employee table
BAdd emp_id as a foreign key column in Project table
CCreate a new table WorksOn with columns emp_id and proj_id as foreign keys
DMerge Employee and Project tables into one
Step-by-Step Solution
Solution:
  1. Step 1: Understand many-to-many relationships

    Many-to-many means multiple employees can work on multiple projects and vice versa.
  2. Step 2: Map many-to-many to tables

    This requires a new table (junction table) that holds foreign keys from both Employee and Project tables.
  3. Final Answer:

    Create a new table WorksOn with columns emp_id and proj_id as foreign keys -> Option C
  4. Quick Check:

    Many-to-many = junction table with two foreign keys [OK]
Quick Trick: Many-to-many needs a new table with two foreign keys [OK]
Common Mistakes:
MISTAKES
  • Adding foreign key to only one table
  • Merging unrelated tables
  • Ignoring the need for a junction table

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More SQL Quizzes