Reputation: 3
I get this error when I try to add the foreign key :
"ORA-00904: "BR_ID": invalid identifier"
create table Branch9
(br_id number NOT NULL,br_name varchar2(25) NOT NULL ,br_address varchar2(30),PRIMARY KEY(br_id))
create table Employee9
(emp_id number NOT NULL,emp_name varchar2(25) NOT NULL UNIQUE,emp_address varchar2(30),emp_age number,emp_dob date,emp_salary number,PRIMARY KEY(emp_id))
ALTER TABLE Employee9
ADD FOREIGN KEY (br_id) REFERENCES Branch9 (br_id);
Is it anything related to NOT NULL
constraint added to br_id?
Upvotes: 0
Views: 97
Reputation: 21657
br_id
has to be in Employee9
table:
This is how you add it:
ALTER TABLE Employee9 ADD br_id number NOT NULL;
Then you can do:
ALTER TABLE Employee9
ADD CONSTRAINT fk_br_id FOREIGN KEY (br_id) REFERENCES Branch9 (br_id);
Upvotes: 0
Reputation: 146450
There's no br_id
column in Employee9
, is there?:
create table Employee9 (
emp_id number NOT NULL,
emp_name varchar2(25) NOT NULL UNIQUE,
emp_address varchar2(30),
emp_age number,
emp_dob date,
emp_salary number,
PRIMARY KEY(emp_id)
)
Upvotes: 0