Chapter 3 of 10All chapters
Chapter 3 of 10
Keys
Identity and reference.
Primary keys
A primary key identifies a row uniquely and permanently. A generated id is usually better than a natural value, because natural values such as emails and phone numbers change.
- Sequential integers are compact; UUIDs can be generated anywhere without coordination.
- A key should never carry meaning that might need editing.
Foreign keys
A foreign key points at another table's primary key and can be enforced by the database. That enforcement is the difference between a relationship and a hopeful convention.