A. Missing parentheses around the composite key columns.
B. student_id and course_id cannot be primary keys.
C. PRIMARY KEY must be declared after all columns.
D. Composite keys require UNIQUE keyword instead.
Solution
Step 1: Check syntax for composite primary key
Composite keys require parentheses around the column list in PRIMARY KEY declaration.
Step 2: Identify error in given SQL
The statement uses PRIMARY KEY student_id, course_id without parentheses, causing syntax error.
Final Answer:
Missing parentheses around the composite key columns. -> Option A
Quick Check:
Composite keys need parentheses [OK]
Hint: Always use parentheses for composite primary keys [OK]
Common Mistakes:
Omitting parentheses in PRIMARY KEY clause
Confusing primary key with unique constraint
Placing PRIMARY KEY before column definitions
5. 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?
hard
A. (class_date, session)
B. (student_id, class_date)
C. (student_id, class_date, session)
D. (student_id, session)
Solution
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.
Step 2: Choose composite key covering all uniqueness factors
Composite key must include student_id, class_date, and session to enforce this rule.
Final Answer:
(student_id, class_date, session) -> Option C
Quick Check:
Composite key covers all uniqueness columns [OK]
Hint: Include all columns that define uniqueness in composite key [OK]