A composite key is a primary key that consists of two or more attributes that uniquely identify a record.
Explanation:
- Used when a single column is insufficient for uniqueness.
- Common in junction tables that handle many-to-many relationships.
Example SQL Composite Key:
sqlCopyEditCREATE TABLE Enrollment (
student_id INT,
course_id INT,
enrollment_date DATE,
PRIMARY KEY (student_id, course_id)
);
Here, student_id
and course_id
together form a composite key.
Leave a Reply