SQL DDL and DML/Define unique constraint

Ensure a column or column set stays unique.

Section: Constraints and Indexes

Define unique constraint

sql
sql
ALTER TABLE users
ADD CONSTRAINT uq_users_email UNIQUE (email);
Explanation

Unique constraints prevent duplicate values.

Learn the surrounding workflow

Compare similar commands or jump into common fixes when this command is part of a bigger troubleshooting path.

Related commands

Same sheet · prioritizing Constraints and Indexes
Define primary key
Mark a column as the main row identifier.
OpenIn sheetsqlsame section
Add check constraint
Restrict column values with a boolean rule.
OpenIn sheetsqlsame section
Create index
Add an index to improve lookup performance.
OpenIn sheetsqlsame section
Create composite index
Index multiple columns together.
OpenIn sheetsqlsame section
Add a constraint
Attach a foreign key or check constraint after table creation.
OpenIn sheetsql1 tag match
Create table
Define a new table with columns and constraints.