Skip to content

UNIQUE

The UNIQUE constraint ensures that all values in a column are unique. This means that no two rows in the table can have the same value for that column. For example, consider a table students with a column student_id that should be unique. The UNIQUE constraint can be applied as follows:

sql
CREATE TABLE students (
    student_id INT UNIQUE,
    first_name VARCHAR(50),
    last_name VARCHAR(50)
);

In this case, the student_id column must have a unique value for every row in the students table.

nametype
student_idINT
first_nameVARCHAR(50)
last_nameVARCHAR(50)

In the table above, each row has a unique value for the student_id column, as required by the UNIQUE constraint.