All courses › Databases, Networks and Security › Tables and keys

Tables and keys

A relational database stores data in tables with rows and columns. The primary key identifies each row uniquely, and a foreign key points to the primary key of another table. That is how exams, for example, are linked to the right student.

Exam.student_id→Student.id\text{Exam.student\_id} \rightarrow \text{Student.id}a foreign key points to a primary key

Symbols

PK\text{PK}primary key: unique per row
FK\text{FK}foreign key: link to another table

Example

Student(id, name) and Exam(id, student_id, course, grade):

one student can have many exams, but each exam belongs to one student.

Store each fact in one place. Then it cannot get out of step with itself.
Practise relational databases and SQL for free →

SELECT and WHERE →

Part of Databases, Networks and Security: Relational databases and SQL.