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

Home -> Community -> Mailing Lists -> Oracle-L -> Re: Error enabling FK constraint

Re: Error enabling FK constraint

From: Tom Tyson <tomtysonjr_at_yahoo.com>
Date: Wed, 20 Sep 2000 15:06:26 -0700 (PDT)
Message-Id: <10625.117508@fatcity.com>


Helmut

Before this question is answered, shouldn't the foreign key contain both the companyid and the storelocid, since these are both part of the primary key. Otherwise, you cannot determine the correct storelocid between companylocid's. I might be reading too much into this.. but going on my assumption you would do the following query to get a list of all the rows that don't have a primary key matching with both a companyid and a storelocid from the tb_dept table to the tb_stores table:

SELECT b.companyid, b.storelocid
 FROM tb_dept a, tb_stores b
 WHERE a.companyid = b.companyid (+) AND

       a.storelocid = b.storelocid (+) AND
       (b.companyid IS NULL OR
        b.storelocid IS NULL)

( I believe this SQL is right.. typed it up without testing it :) )

If you really wanted the foriegn key to be as you stated, I would have run the following query:

SELECT b.storelocid
 FROM tb_dept a, tb_stores b
 WHERE a.storelocid = b.storelocid (+) AND

       b.storelocid IS NULL)

Hope that helps
Tom Tyson  


Do You Yahoo!? Received on Wed Sep 20 2000 - 17:06:26 CDT

Original text of this message

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