Backendintermediate

Primary Key

A unique identifier for each row in a database table, like a student ID number.

Detailed Explanation

A primary key is a column (or columns) that uniquely identifies each row in a table. No two rows can have the same primary key value. Primary keys are required for databases to function—they allow you to reference specific rows and update/delete precisely.

Common primary keys are IDs (numeric or UUID), email addresses, or usernames. The database enforces uniqueness—it will not let you insert a duplicate. Primary keys are also the fastest way to look up rows. You define them using SQL CREATE TABLE statements.

Every table should have a primary key. When you create a table, you explicitly mark one column (or combination of columns) as PRIMARY KEY. Other tables reference this with foreign keys.

In modern databases like Supabase, primary keys are typically UUIDs — long random strings that are globally unique and more secure than auto-incrementing numbers.

Code Example

sql

Ready to Build Something Real?

We give you the skills to build, deploy, and own a full product. Professional stack, AI co-pilot, no coding background required.