Re: Problem with enforcement of a 'UNIQUE' constraint
Date: 26 Feb 1995 20:53:27 -0500
Message-ID: <3irban$nic_at_pipe4.pipeline.com>
In comp.databases.oracle jb2_at_qdot.qld.gov.au (John Blackburn) said:
>Carolyn Giberson (giber_at_pollux.cs.uga.edu) wrote:
>
>> I'm working on an object-oriented front-end for Oracle as a thesis
>> project and am observing curious behavior with enforcement of a
>> 'UNIQUE' constraint on an attribute. Here is a short description of
>> the behavior:
>> If I create a table "by hand" like so:
>> create table t1
>> (n number UNIQUE NOT NULL);
>> and attempt to insert records with duplicate values for 'n', Oracle
>> complains about a constraint violation, as it should.
>> If, however, I have my program construct the identical table creation
>> command and send to Oracle, the table is apparently created without
>> the 'UNIQUE' constraint. I can insert records with duplicate values
>> for 'n', and Oracle does *not* complain.
>> Can anyone suggest why I am observing this difference in behavior, and
>> how I might persuade Oracle to enforce this constraint?
>
>Try creating a unique index on the unique column:
>
>create unique index x1 on t1 (n);
>
Before Oracle7, you would need to create an index to enforce the uniqueness of the column, as above. If you are using 7.x, then Oracle _should_ create the index for you as a result of specifying UNIQUE for the column.
Someone please correct me if I'm wrong about this.
Aaron Barbour
abarbour_at_pipeline.com
Infolution, Inc.
New York, NY
212.978.0081
Received on Mon Feb 27 1995 - 02:53:27 CET
