Oracle FAQ Your Portal to the Oracle Knowledge Grid
HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US
 

Home -> Community -> Usenet -> c.d.o.server -> Re: How to create a uniqueness constraint based on two fields?

Re: How to create a uniqueness constraint based on two fields?

From: DA Morgan <damorgan_at_x.washington.edu>
Date: Wed, 26 Jan 2005 10:33:31 -0800
Message-ID: <1106764257.248395@yasure>


Thomas Kellerer wrote:

> On 26.01.2005 13:25 Ramon wrote:
> 
> 

>>I have read in this NG that there is a way to to have a
>>uniqueness constraint based on two or more fields.
>>
>>Just to make sure that there are no confusions, I'll
>>provide a very simple example. Suppose I am using SQL*Loader
>>and there is a record with FIRST_NAME='JOHN' and LAST_NAME='SMITH'.
>>
>>Subsequent records with FIRST_NAME='JOHN' will be accepted.
>>Subsequent records with LAST_NAME='SMITH' will be accepted.
>>
>>However, any record containing JOHN SMITH will be rejected for
>>violating the constraint.
>>
>>TIA,
>>
>>-Ramon F Herrera
>>
> 
> 
> CREATE UNIQUE INDEX ON the_table (first_name, last_name);
> 
> should do it, I guess.
> 
> Thomas

While your answer is technically correct there is almost not good reason for ever creating a unique index in Oracle. Unique indexes, unlike unique constraints are not as well documented in the data dictionary and can't be deferred.

-- 
Daniel A. Morgan
University of Washington
damorgan_at_x.washington.edu
(replace 'x' with 'u' to respond)
Received on Wed Jan 26 2005 - 12:33:31 CST

Original text of this message

HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US