Account
Categories

UNIQUE Constraint


The UNIQUE constraint is a type of constraint that is applied only to columns. It checks whether a column contains duplicate values or not.
Here, duplicate value means a value that already exists in another row of the same column.
If any attempt is made to insert a duplicate value into that column, it will result in an error.
In MySQL, NULL values are allowed, and you can insert multiple NULLs in a column with the UNIQUE constraint.

Syntax:

CREATE TABLE table_name (
    column_name data_type UNIQUE
);