A relational database stores structured data in tables and connects those tables through common attributes. Each table represents an entity, while keys define relationships and help maintain accurate, consistent data.
How a Relational Database Is Structured
A table consists of records (rows) and fields (columns). Each record represents one instance of an entity, while each field stores one type of attribute.
| Component | Purpose | Example |
|---|---|---|
| Table | Stores data about one entity type | STUDENT |
| Record | Stores one instance of that entity | One student's details |
| Field | Stores one attribute | StudentName |
| Primary key | Uniquely identifies each record | StudentID |
| Foreign key | References a primary key in another table | StudentID in ENROLMENT |
For example, a school database could contain STUDENT and COURSE tables. Because one student may take many courses and one course may contain many students, this is a many-to-many relationship. It can be resolved using an ENROLMENT table:
- STUDENT(StudentID, StudentName)
- COURSE(CourseID, CourseName)
- ENROLMENT(StudentID, CourseID)
StudentID and CourseID in ENROLMENT are foreign keys. Together, they can form a composite primary key, ensuring that the same student-course pairing is not entered twice.
Relational databases reduce unnecessary duplication by separating data into related tables. This supports data integrity: for example, referential integrity prevents an ENROLMENT record from referring to a StudentID that does not exist in STUDENT. Data can then be retrieved or modified using SQL operations such as SELECT, INSERT, UPDATE, and DELETE.
A common misconception is that any spreadsheet is a relational database. A spreadsheet may display rows and columns, but a relational database formally uses keys, relationships, integrity constraints, and a database management system.
Exam Technique
In an IB response, define the table structure, distinguish primary and foreign keys, and explain how the keys create a relationship. When given a scenario, identify entities and attributes before proposing tables; do not simply list data fields without showing their keys.