Suggest an editImprove this articleRefine the answer for “How do you make a field unique in a row?”. Your changes go to moderation before they’re published.Approval requiredContentWhat you’re changing🇺🇸EN🇺🇦UAPreviewTitle (EN)Short answer (EN)To make a field unique, use the `UNIQUE` constraint, which forbids repeated values in that column - it can be set when the table is created (`Name VARCHAR(50) NOT NULL UNIQUE`) or added later via `ALTER TABLE ... ADD CONSTRAINT ... UNIQUE (...)`. **Key point:** `UNIQUE` allows `NULL` (in most DBMSs), but repeated non-null values are forbidden; a combination of several fields can also be made unique, e.g. `(Name, Age)`.Shown above the full answer for quick recall.Answer (EN)ImageTo make a field unique, the `UNIQUE` **constraint** is used, forbidding repeated values in that column. **Ways to set uniqueness:** ### 1. When creating the table ```sql CREATE TABLE Employees ( ID INT PRIMARY KEY, Name VARCHAR(50) NOT NULL UNIQUE, -- a unique field Age INT ); ``` - The `Name` field can't repeat within the table. ### 2. By adding a constraint to an existing table ```sql ALTER TABLE Employees ADD CONSTRAINT unique_name UNIQUE (Name); ``` - `ALTER TABLE` can be used to make an existing column unique. **Notes:** - `UNIQUE` allows **NULL** (in most DBMSs), but repeated non-null values are forbidden. - A **combination of several fields can be made unique**, e.g. `(Name, Age)`, so that combination of values doesn't repeat. > Put simply, `UNIQUE` guarantees that **a column's value won't repeat** within the table.For the reviewerNote to the moderator (optional)Visible only to the moderator. Helps review go faster.