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

Home -> Community -> Usenet -> c.d.o.misc -> Re: Creating Constraints question

Re: Creating Constraints question

From: Jonathan Gennick <jonathan_at_gennick.com>
Date: Tue, 07 Mar 2000 03:17:35 GMT
Message-ID: <38ca6bee.18401349@netnews.worldnet.att.net>


On Mon, 06 Mar 2000 23:23:34 GMT, argosy22_at_my-deja.com wrote:

>and the primary keys are different:

That right there is why you are getting the error message when you create the foreign key constraint.

>If I make a constraint where one table references the other,
>must it reference the entire primary key, or not?

They must reference either a primary key, or a unique key. For example, the following should work:

CREATE TABLE parent (
  parent_id number,
  constraint parent_id_unique
    unique (parent_id)
  );

create table child (
  child_id number,
  parent_id number,
  constraint child_has_parent
    foreign key (parent_id) references parent (parent_id)   );

If you don't have either a unique or a primary key in your "parent" table that matches the foreign key in your child table, then you can do one of two things (that I'm aware of): You can create a trigger, or you can create a third table.

Jonathan



jonathan_at_gennick.com
http://gennick.com
Brighten the Corner Where You Are Received on Mon Mar 06 2000 - 21:17:35 CST

Original text of this message

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