Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Creating a table with unique fields

Dude!Sep 5 2016 — edited Sep 6 2016

According to my findings, multiple unique columns in a table work in a collective fashion. For example:

SQL> create table demo (

name varchar2(20),

col1 varchar2(15),

col2 varchar2(15),

constraint demo_uc

unique (col1, col2) );

SQL> insert into demo values ('fritz', 'red', 'green');

1 row created.

SQL> insert into demo values ('joe', 'red', 'blue');

1 row created.

SQL> insert into demo values ('joe', 'red', 'green');

insert into demo values ('joe', 'red', 'green')

*

ERROR at line 1:

ORA-00001: unique constraint (OPS$ALIVE.DEMO_UC) violated

Is it possible to create a table where each field has to be unique? So for example that neither col1 nor col2 can have duplicate fields?

Thanks!

This post has been answered by unknown-7404 on Sep 5 2016
Jump to Answer
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Oct 4 2016
Added on Sep 5 2016
7 comments
2,189 views