Bird
0
0

Which SQL command correctly creates a junction table Enrollment linking Student and Class tables by their IDs?

easy📝 Syntax Q3 of 15
SQL - Table Relationships
Which SQL command correctly creates a junction table Enrollment linking Student and Class tables by their IDs?
ACREATE TABLE Enrollment (StudentID INT, ClassID INT, PRIMARY KEY (StudentID, ClassID));
BCREATE TABLE Enrollment (ID INT PRIMARY KEY, StudentID INT, ClassID INT);
CCREATE TABLE Enrollment (StudentID INT UNIQUE, ClassID INT UNIQUE);
DCREATE TABLE Enrollment (StudentID INT, ClassID INT);
Step-by-Step Solution
Solution:
  1. Step 1: Identify junction table structure

    It must include foreign keys from both tables and a composite primary key.
  2. Step 2: Analyze options

    CREATE TABLE Enrollment (StudentID INT, ClassID INT, PRIMARY KEY (StudentID, ClassID)); correctly defines StudentID and ClassID with a composite primary key.
  3. Final Answer:

    CREATE TABLE Enrollment (StudentID INT, ClassID INT, PRIMARY KEY (StudentID, ClassID)); -> Option A
  4. Quick Check:

    Composite PK enforces uniqueness of pairs [OK]
Quick Trick: Composite primary key enforces unique pairs [OK]
Common Mistakes:
MISTAKES
  • Using surrogate key instead of composite primary key
  • Assigning UNIQUE constraints incorrectly
  • Omitting primary key definition

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More SQL Quizzes