MySQL database makes a field that is not the primary key UNIQUE in the process of using MySQL data, sometimes we need a field that is not the primary key is not repeated, this requires the use of SQL UNIQUE constraints.
The following is an introduction from w3school:
The UNIQUE constraint uniquely identifies each record in the database table.
UNIQUE and primary key constraints provide uniqueness guarantee for columns or column sets.
Primary key has automatically defined UNIQUE constraints.
Note that each table can have multiple UNIQUE constraints, but each table can have only one primary key constraint.
The following creates a UNIQUE constraint in the "Id_P" column when creating a "Persons" table:
MySQL:
Create table Persons (Id_P int not null, LastName varchar (255) not null, FirstName varchar (255), Address varchar (255), City varchar (255 ),UNIQUE (Id_P)
)
Details: SQL UNIQUE constraints