In the process of using MySQL data, sometimes we need a field that is not the primary key is not duplicated, this time will use the SQL UNIQUE constraint.
Here is a brief excerpt from W3school:
Unique constraints uniquely identify each record in a database table.
Both the unique and PRIMARY KEY constraints provide a unique guarantee for a column or column collection.
PRIMARY KEY has a UNIQUE constraint that is automatically defined.
Note that each table can have multiple UNIQUE constraints, but there can be only one PRIMARY KEY constraint per table.
The following creates a UNIQUE constraint in the "id_p" column when the "Persons" table is created:
Mysql:
CREATE TABLE Persons (id_p int not null,lastname varchar (255) not null,firstname varchar (255), Address varchar (255), City VA Rchar (255), UNIQUE (Id_P)
)
More information: SQL UNIQUE constraints