Composite Key
A composite key is two or more columns together as the uniqueness rule. PRIMARY KEY (roll, subject) on marks: the same student can have Maths and English, but not two Maths rows.
FOREIGN KEYs to a composite PK must include all those columns. Harder to join. An AUTO_INCREMENT id as PK plus UNIQUE (roll, subject) is often easier.
Trap: composite PK when a simple id would do. Trap: only putting roll as PK on marks so a student can have only one subject.
On the example next to this theory — Composite Key — keys and constraints protect data integrity; indexes speed lookups.
students.id ← PK (unique)
▲
│ FK
marks.student_idPRIMARY KEY (roll, subject) — one row per student per subject.