Results 1 to 3 of 3
  1. #1
    Join Date
    Dec 2003
    Posts
    2

    Unanswered: need foreign key in 2 tables

    Ok I am very new to design and am plugging along just fine till now.


    I have 2 associative tables with a parent in between.

    I need the primary key(of the parent) to be a foreign key in both tables.

    I can not do this? orc will not let me. I have it in one table as a constraint but when I try to create the other table or alter it with the same constraint refering to the same primary key it wont let me.

    Says: name used already by ab existing constraint.

    How do I solve this?

    Nothing to complicated or if it is pleas explaine so that a begineer like me can under stand.

    THANK YOU VERY MUCH!

  2. #2
    Join Date
    Dec 2003
    Posts
    18

    Re: need foreign key in 2 tables

    Hi,


    create table parent(no number, name varchar2(20));
    alter table parent add constraint pk_parent_no primary key(no);
    create table girls (no number, name varchar2(20));
    alter table girls add constraint pk_parent_no primary key(no);
    error:= name already used by an existing constraint;
    bcoz i am trying to give the same name for primary key;
    alter table girls add constraint fk_girl_no foreign key(no) references parent(no);
    alter table boy add constraint fk_girl_no foreign key(no) references parent(no);
    errors:=ORA-02264: name already used by an existing constraint;
    bcoz i am trying to give the same name for foreign key which already exist with girl table
    so you have to choose different name i.e:-
    alter table boy add constraint fk_boy_no foreign key(no) references parent(no);




    Originally posted by blacktire
    Ok I am very new to design and am plugging along just fine till now.


    I have 2 associative tables with a parent in between.

    I need the primary key(of the parent) to be a foreign key in both tables.

    I can not do this? orc will not let me. I have it in one table as a constraint but when I try to create the other table or alter it with the same constraint refering to the same primary key it wont let me.

    Says: name used already by ab existing constraint.

    How do I solve this?

    Nothing to complicated or if it is pleas explaine so that a begineer like me can under stand.

    THANK YOU VERY MUCH!

  3. #3
    Join Date
    Dec 2003
    Posts
    2
    I knew it was something really simple but after being at ths screen for 16 hrs I could not think of it.


    This worked just fine thank you!!!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •