Database Design and Theory

Primary and Foreign Keys

Why a table has one primary key, how composite keys work and how keys link tables.

Can PK and FK be the same?

A column can be both a primary key and a foreign key, and this is common in one-to-one and junction tables. Here is when it works and when it does not.

2 min read

What is a composite primary key?

A composite primary key is a primary key made of two or more columns that together identify each row. Here is the syntax, an example and common mistakes.

2 min read

What is a PK and FK?

A primary key uniquely identifies each row in a table, and a foreign key points to a key in another table. Here is how the two work together in MySQL.

2 min read

Related topics

More in database design and theory