What Are the Differences Between Unique Constraints and Unique Indexes?

Example: Create a composite index for two columns, which is not required to be a unique index.

1
2
CREATE TABLE t (n1 number,n2 number);
CREATE INDEX t_idx ON t(n1,n2);

You can use the index t_idx created in the preceding example to create a unique constraint t_uk, which is unique only on column n1. A unique constraint is stricter than a unique index.

1
ALTER TABLE t ADD CONSTRAINT t_uk UNIQUE (n1) USING INDEX t_idx;