Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
Home -> Community -> Usenet -> c.d.o.misc -> Re: SQL question
Andy Hassall wrote:
> On Wed, 04 May 2005 08:56:16 +0200, Sybrand Bakker wrote:
>> Andreas Mosmann<keineemails_at_gmx.de> wrote: >> >>>Only for question, did anybody try this out for self referencing tables, >>>especially for those, that contain a selfreference in one row? >> >>Selfreference in one row has never been allowed in Oracle, the >>reference being cyclic.
Agreed; a field that is foreign keyed to itself appears to have limited utility. But the OP was asking about a table with two fields, one of which is foreign keyed to the other. Adapting your nomenclature, that seems to work:
SQLWKS> create table t (
2> c1 number not null, 3> c2 number not null, 4> constraint t_pk primary key (c1), 5> constraint t_fk1 foreign key (c2) references t (c1) );Statement processed.
SQLWKS> insert into t values (2,3); ORA-00001: unique constraint (T_PK) violated SQLWKS> insert into t values (3,2);
1 1 2 2 3 2
Not sure what others are talking about with regard to self refrencing being disallowed. I'm using 9.2/W2k3 if that makes any difference.
-- //-Walt // //Received on Wed May 04 2005 - 16:49:41 CDT