Primary keys and foreign keys are the glue of relational databases. One identifies a row uniquely; the other creates a relationship between tables. Every JOIN you will ever write in analytics depends on these two concepts.
Key Points
- Primary key: unique identifier of a row in its own table (e.g., customers.id)
- Foreign key: a column that references a primary key in another table (e.g., orders.customer_id)
- A table has only one primary key but can have many foreign keys
- Primary keys reject NULLs; foreign keys may allow them
- Foreign keys can cascade updates/deletes with ON DELETE CASCADE
- Together they enable one-to-many and many-to-many relationships
.png)