# Primary Key

> A column with a different value in each row. That is how one row is found.

**Field:** Software Development  
**Category:** Databases  
**Also known as:** PK, Primary Key Column

## Think of it like

Think of it like the number on a shirt in a team. Two kids can share a name, but not a number.

## Definition

A primary key is the column that gives each row in a table its own unique value. No two rows can have the same key, and it can never be empty. It is often a simple number, like id, that the database counts up by itself. Other tables use it to point at a row without confusion. Every table should have one.

## Example

Two customers are both called Jack. Their ids are 2 and 7, so the shop never sends the wrong one an order.

## Example code

```sql
INSERT INTO customers (id, name) VALUES (1, 'Zoe');
-- Error: UNIQUE constraint failed: customers.id
```

There is a row 1 already, so a second one is refused.

## Why it matters

Without a unique key, you cannot safely change or delete one row. You might hit two.

## Common mistake

Using something that can change, like an email, as the key. When it changes, every link to it breaks.

## Three principles

- **Unique.** No two rows share it.
- **Never empty.** Every row must have one.
- **Never changes.** Other tables rely on it.

## Related terms

- [Foreign Key](https://learn.benibix.com/term/development/foreign-key)
- [Database Table](https://learn.benibix.com/term/development/database-table)
- [Row](https://learn.benibix.com/term/development/row)
- [Database Index](https://learn.benibix.com/term/development/database-index)
- [Universally Unique Identifier (UUID)](https://learn.benibix.com/term/development/uuid)

## Told apart from

- [Primary Key vs Foreign Key](https://learn.benibix.com/compare/primary-key-vs-foreign-key): A primary key names each row in its own table. A foreign key sits in another table and points back to that name.

---

Source: https://learn.benibix.com/term/development/primary-key
Author: Behnia Zarei (a developer in Vienna, Austria, who builds and teaches data, AI and business intelligence at BENIBIX)
Publisher: BENIBIX Learn (https://learn.benibix.com/)
Last updated: 2026-11-19
Licence: CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Quote freely with attribution.
