Re: Difference between unique constraint and unique index?
aj wrote:
> DB2 WSE 8.1 FP5
> Red Hat AS 2.1
>
> What is the difference between adding a unique constraint like:
>
> ALTER TABLE <SCHEMA>.<TABLE> ADD CONSTRAINT CC1131378283225 UNIQUE (
> <COL1>) ;
>
> and adding a unique index like:
>
> CREATE UNIQUE INDEX <SCHEMA>.<BLAH> ON <SCHEMA>.<TABLE> (<COL1> ASC)
> PCTFREE 10 MINPCTUSED 10;
>
> Just curious.
>
> TIA
>
> aj
In addition to other replies, there's another difference between the
two.
DB2 allows a "unique index" to contain a single "null" value. So DB2
lets you create a "unique index" on a nullable column.
However, in contrast, if you have a column that has a "unique
constraint" then DB2 forces that column to be "not-null". Db2 requires
any column in either a primary-key or a unique-key to be mandatory (not
null). |