Skip to content

UNIQUE

CREATE TABLE Employees (
ID INT UNIQUE,
Name VARCHAR(255)
);
INSERT INTO Employees (ID, Name) VALUES (1, 'John');
INSERT INTO Employees (ID, Name) VALUES (1, 'David');
ERROR 1062: Duplicate entry '1' for key 'ID'

In the given example, the SQL UNIQUE constraint is used to prevent two entries from having the same ID in the ‘Employees’ table. Duplicate insertion for ID ‘1’ is attempted and results in the displayed error, since UNIQUE constraint ensures the uniqueness of the data in a column.