SQL UNIQUE


The UNIQUE constraint uniquely identifies each record in a database table.

The UNIQUE and PRIMARY KEY constraints both provide a guarantee for uniqueness for a column or set of columns.

A PRIMARY KEY constraint automatically has a UNIQUE constraint defined on it.

Note That you can have many UNIQUE constraints per table, but only one PRIMARY KEY constraint per table.

SQL UNIQUE Constraint on CREATE TABLE

The following SQL creates a UNIQUE constraint on the "c_id" column when the "customer" table is created:

CREATE TABLE customer
(
c_id INT NOT NULL UNIQUE,
lastName VARCHAR(255) NOT NULL,
firstName VARCHAR(255),
address VARCHAR(255),
)

Share this article on