Skip to Main Content

SQL Developer Data Modeler

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!

EA2: How to make a self referencing fk optional?

RafuDec 21 2010 — edited Dec 21 2010
How an optional self referencing foreign key may be designed when part of the foreign key is also part of the referenced primary key.

In - Table Properties - Foreign Keys - uncheck Mandatory - Apply complains that FK cannot be optional because some columns are part of PK.
In column properties Mandatory is checked and grayed. Not possible to change.

This is not something I liked to see.


Reverse engineering such model marks the foreign key mandatory in the model. As it should not be. The other foreign key column is optional as it should.
CREATE TABLE TABLE_1 
    ( 
     a NUMBER (4)  NOT NULL , 
     aversion NUMBER (4)  NOT NULL , 
     parentversion NUMBER (4) 
    ) 
;


ALTER TABLE TABLE_1 
    ADD CONSTRAINT TABLE_1_PK PRIMARY KEY ( a, aversion ) ;



ALTER TABLE TABLE_1 
    ADD CONSTRAINT TABLE_1_TABLE_1_FK FOREIGN KEY 
    ( 
     a,
     parentversion
    ) 
    REFERENCES TABLE_1 
    ( 
     a,
     aversion
    ) 
;
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jan 18 2011
Added on Dec 21 2010
2 comments
890 views