Bird
0
0

A developer writes: CREATE TABLE Enrollment(student_id INT, course_id INT, PRIMARY KEY(student_id)); to represent many-to-many between Student and Course. What's wrong?

medium📝 Debug Q7 of 15
SQL - Table Relationships
A developer writes: CREATE TABLE Enrollment(student_id INT, course_id INT, PRIMARY KEY(student_id)); to represent many-to-many between Student and Course. What's wrong?
ATable name is invalid
BForeign keys are missing
CData types are incorrect
DPrimary key should include both student_id and course_id
Step-by-Step Solution
Solution:
  1. Step 1: Understand many-to-many junction table keys

    Junction tables need composite primary keys including both foreign keys.
  2. Step 2: Check primary key definition

    Only student_id is primary key here; course_id should be included too.
  3. Final Answer:

    Primary key should include both student_id and course_id -> Option D
  4. Quick Check:

    Composite PK needed for many-to-many [OK]
Quick Trick: Many-to-many tables need composite primary keys [OK]
Common Mistakes:
MISTAKES
  • Using single column as primary key
  • Omitting foreign keys
  • Incorrect data types

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More SQL Quizzes