beginner
Unique Constraint
4 min readLast updated: 2026-07-23
Overview
A UNIQUE constraint ensures that all values in a column or set of columns are distinct across all table rows.
Code Examples
SQL
sql
CREATE TABLE users (
user_id INT PRIMARY KEY,
email VARCHAR(255) UNIQUE
);
Summary
The UNIQUE constraint prevents duplicate column values while allowing NULL values depending on the RDBMS.