Skip to content

Unique Constraint

Easy — everyone uses thisDatabase

ELI5 — The Vibe Check

A unique constraint tells the database 'no two rows can have the same value in this column.' Perfect for email addresses — you do not want two users with the same email. The database will flat-out reject duplicate inserts.

Real Talk

A UNIQUE constraint ensures that all values in a column (or combination of columns) are distinct across all rows in the table. Unlike a primary key, a column with a UNIQUE constraint can contain NULL values (in most databases). It automatically creates an index on the column.

Show Me The Code

CREATE TABLE users (
  id SERIAL PRIMARY KEY,
  email TEXT UNIQUE NOT NULL
);

When You'll Hear This

"Put a unique constraint on the username column." / "The insert failed because of a unique constraint violation."

Made with passive-aggressive love by manoga.digital. Powered by Claude.