Loading lesson path
Concept visual
Start at both ends
❮ SQL Keywords
constraint ensures that all values in a column are unique.
The following SQL creates a UNIQUE constraint on the "ID" column when the "Persons" table is created:
Formula
SQL Server / Oracle / MS Access:( ID int NOT NULL UNIQUE, LastName varchar(255) NOT NULL, FirstName varchar(255),
);( ID int NOT NULL, LastName varchar(255) NOT NULL, FirstName varchar(255), Age int, UNIQUE (ID)
);To name a UNIQUE constraint, and to define a UNIQUE constraint on multiple columns, use the following SQL syntax:
Formula
MySQL / SQL Server / Oracle / MS Access:( ID int NOT NULL, LastName varchar(255) NOT NULL, FirstName varchar(255), Age int, CONSTRAINT UC_Person UNIQUE (ID,LastName)
);To create a UNIQUE constraint on the "ID" column when the table is already created, use the following SQL:
Formula
MySQL / SQL Server / Oracle / MS Access:ADD UNIQUE (ID);To name a UNIQUE constraint, and to define a UNIQUE constraint on multiple columns, use the following SQL syntax:
Formula
MySQL / SQL Server / Oracle / MS Access:ADD CONSTRAINT UC_Person UNIQUE (ID,LastName);To drop a UNIQUE constraint, use the following SQL:
DROP INDEX UC_Person;Formula
SQL Server / Oracle / MS Access:DROP CONSTRAINT UC_Person;❮ SQL Keywords