41. Composite primary key

DBMS Published Updated 0 Views Verified
Create an enrollment table where the same student cannot enroll in the same course twice.
Looking for the latest Sarkari Result 2026 updates? Check the latest government exam results, merit lists and result updates on Sarkari Resultess.
Sarkari Resultess
Questions & Answers

Answer & Explanation

4 Answers
Verified Correct Answer

Option A

CREATE TABLE enrollments (student_id BIGINT NOT NULL, course_id BIGINT NOT NULL, PRIMARY KEY (student_id, course_id));
Additional Explanation
Correct implementation. Prefer parameterized queries in application code, validate affected rows for UPDATE/DELETE, and use transactions for related writes.
Sarkari Resultess
Editorial Answer 1
Verified

Option B

PRIMARY KEY (student_id), PRIMARY KEY (course_id);
Additional Explanation
This option is incorrect for the stated requirement.
Sarkari Resultess
Editorial Answer 2
Verified

Option C

PRIMARY KEY (student_id, course_id, created_at) without needing created_at;
Additional Explanation
This option is incorrect for the stated requirement.
Sarkari Resultess
Editorial Answer 3
Verified

Option D

UNIQUE (student_id) only;
Additional Explanation
This option is incorrect for the stated requirement.
Sarkari Resultess
Editorial Answer 4