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: Help: Cross-Referenced Foreign Keys

Re: Help: Cross-Referenced Foreign Keys

From: MarkP28665 <markp28665_at_aol.com>
Date: 13 Dec 1998 23:02:11 GMT
Message-ID: <19981213180211.07839.00005796@ng20.aol.com>


Chuck is having trouble trying to create two tables each of which has a foreign key, FK, reference to the other. Your problem is that you are trying to create a FK reference to a non-existent table so create the tables first and then use the alter table statement to add the FK's.

Please check the SQL manual for the syntax but it is something like: alter table table_1
 add constraint foreign_key_name
 references talbe_2(col1,col2,...N) ;

From: c_price_at_interaccess.com >>
Create table Staff (
  StaffNo number not null primary key,
  Dept number not null,
    foreign key (Dept) references Department(Dept)
);

create table Department (
  Dept number not null primary key,
  Manager number,
    foreign key (Manager) references Staff(StaffNo)
);

In this case, each staff must be assigned a department and each department may be assigned a manager (who must exist in the Staff table if assigned).

As a new user of Oracle, I'm having trouble implementing this. <<
Mark Powell -- Oracle 7 Certified DBA
- The only advice that counts is the advice that you follow so follow your own advice - Received on Sun Dec 13 1998 - 17:02:11 CST

Original text of this message

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