SQL Database
To guarantee that every value in a column is unique, apply the UNIQUE constraint.
A column’s or a group of columns’ uniqueness is ensured by the UNIQUE and PRIMARY KEY constraints.
A UNIQUE constraint is inherently included in a PRIMARY KEY constraint.
On the other hand, only one PRIMARY KEY constraint and numerous unique constraints are allowed per table.
When the “Persons” table is formed, the UNIQUE constraint on the “ID” column is created with the following SQL:
SQL Server / Oracle / MS Access:
MySQL:
Use the following SQL syntax to construct a unique constraint on multiple columns and to name the constraint:
MySQL / SQL Server / Oracle / MS Access:
Once the table has been established, use the following SQL to create a UNIQUE constraint on the “ID” column:
MySQL / SQL Server / Oracle / MS Access:
ALTER TABLE Persons
ADD UNIQUE (ID);
Use the following SQL syntax to construct a unique constraint on multiple columns and to name the constraint:
MySQL / SQL Server / Oracle / MS Access:
ALTER TABLE Persons
ADD CONSTRAINT UC_Person UNIQUE (ID,LastName);
To remove a UNIQUE constraint, use the SQL code below:
MySQL:
ALTER TABLE Persons
DROP INDEX UC_Person;
SQL Server / Oracle / MS Access:
ALTER TABLE Persons
DROP CONSTRAINT UC_Person;
CodingAsk.com is designed for learning and practice. Examples may be made simpler to aid understanding. Tutorials, references, and examples are regularly checked for mistakes, but we cannot guarantee complete accuracy. By using CodingAsk.com, you agree to our terms of use, cookie, and privacy policy.
Copyright 2010-2024 by Refsnes Data. All Rights Reserved.