UNIQUE Constraint
The UNIQUE
constraint ensures that all values in a column are unique. Unlike the primary key, a table can have multiple unique constraints.
Example: Adding UNIQUE Constraint
CREATE TABLE Cities (
CityID INT PRIMARY KEY,
CityName VARCHAR(50) UNIQUE,
Population INT
);
Explanation: The CityName
column must have unique values, ensuring no two cities have the same name.