Loading subject…
| Composite key | Concatenated key | |
|---|---|---|
| How it is built | Two or more existing columns declared as one key | The values of two or more attributes joined into a single new value |
| Number of columns | Two or more | One |
| Example value | StudentID = 1024 and CourseID = CS01 | EnrolmentCode = 1024-CS01 |
| Searching one part | Direct, because each part is its own column | Needs the string splitting first |
| Typical use | Junction tables resolving a many-to-many relationship | Human-readable reference codes such as an order number or a booking reference |
| Constraint | What it enforces | Example |
|---|---|---|
| PRIMARY KEY | Unique and never NULL | StudentID in Student |
| FOREIGN KEY | The value must exist in the referenced table | StudentID in Enrolment |
| NOT NULL | A value must be supplied | Surname cannot be left blank |
| UNIQUE | No two rows share the value, but NULL is allowed | Email in Member |
| CHECK | The value must satisfy a condition | Quantity > 0 |
| DEFAULT | A value is filled in when none is given | JoinDate defaults to today |
| Table | Columns | Key | Constraints |
|---|---|---|---|
| Student | StudentID, FirstName, LastName, DOB, Email | PK StudentID | All NOT NULL, Email UNIQUE |
| Course | CourseID, CourseName, Credits | PK CourseID | Credits CHECK between 1 and 6 |
| Enrolment | StudentID, CourseID, EnrolmentDate, FinalGrade | Composite PK (StudentID, CourseID) | Both columns FK, FinalGrade allowed NULL until the course ends |