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.
a foreign key points to a primary key
Symbols
| primary key: unique per row | ||
| 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 →
Part of Databases, Networks and Security: Relational databases and SQL.