Tech / SoftwareDepth 0 · Foundation
Primary Key (database)
A unique ID that identifies each record in a table
A primary key is a column (or set of columns) that uniquely identifies each row in a database table. It guarantees uniqueness and is used as the target for foreign key relationships across tables.
Mental modelUniqueness constraint + reference anchor
Where you'll encounter this
- →Database schema design
- →ORM modeling (Prisma, Drizzle)
- →API resource identification
- →Relational data modeling
What breaks when this is misunderstood
- ✕Duplicate records due to missing constraints
- ✕Broken relationships between tables
- ✕Inconsistent data references
- ✕Difficult debugging of data integrity issues
Signals this concept is in play
- ◆PRIMARY KEY constraint in schema
- ◆Unique ID fields (id, uuid, cuid)
- ◆Foreign key references in other tables
- ◆Database errors on duplicate insert