Database
Primary Key (Database)
Added: June 23, 2026
Definition
A Primary Key is a column (or set of columns) in a table that uniquely identifies each record. It must be unique, not null, and only one primary key exists per table (can be composite).
What Problem It Solves
It prevents duplicate records and ensures every row can be uniquely accessed, updated, or deleted without ambiguity.
What Happens If Not Used
- Duplicate rows can exist
- Hard to identify specific records
- Update/Delete anomalies occur
- Data integrity becomes unreliable
Easy Wording
A primary key is a unique ID for each row in a table.
Technical Example
In a student table, each student has a unique Student ID so no two students are confused even if they have the same name. CREATE TABLE Students ( student_id INT PRIMARY KEY, name VARCHAR(100), age INT );