Archive for July 15, 2008

Creating a Unique Constraint in Oracle

Posted in Oracle, Software, pl/sql, programming with tags on July 15, 2008 by Joey

A unique constraint is used to ensure that a singular value occur only once in a column or that a distinctive combination of values occur only once across a series of columns.

Primary keys are themselves unique constraints automatically and can’t be created as unique constraints. Oracle does not permit you to create both a primary key and unique constraint with the same columns.

CREATE TABLE my_table
(my_column datatype default null/not null,
my_column datatype default null/not null,
CONSTRAINT my_constraint UNIQUE (column1, column2, …column_n)
);

Null values are allowed in a unique constraint, provided that the combination of values is unique.