Bird
0
0

Which composite primary key should you define?

hard📝 Application Q15 of 15
SQL - Table Constraints
You have a table Attendance with columns student_id, class_date, and session. You want to ensure each student can only have one attendance record per class date and session. Which composite primary key should you define?
A(class_date, session)
B(student_id, class_date)
C(student_id, class_date, session)
D(student_id, session)
Step-by-Step Solution
Solution:
  1. Step 1: Understand uniqueness requirement

    Each student must have only one record per class date and session, so all three columns combined must be unique.
  2. Step 2: Choose composite key covering all uniqueness factors

    Composite key must include student_id, class_date, and session to enforce this rule.
  3. Final Answer:

    (student_id, class_date, session) -> Option C
  4. Quick Check:

    Composite key covers all uniqueness columns [OK]
Quick Trick: Include all columns that define uniqueness in composite key [OK]
Common Mistakes:
MISTAKES
  • Leaving out session or class_date from key
  • Using only two columns when three needed
  • Confusing foreign keys with primary keys

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More SQL Quizzes