Question
DATABASE : Hi! Please someone help me when I'm trying to make a foreign key relation between branch and staff table I get this error:
DATABASE : Hi! Please someone help me when I'm trying to make a foreign key relation between branch and staff table I get this error:
ALTER TABLE BRANCH ADD FOREIGN KEY (MANAGER_ID, BRANCHID) REFERENCES STAFF(MANAGER_ID, BRANCHID) Error report - ORA-02270: no matching unique or primary key for this column-list 02270. 00000 - "no matching unique or primary key for this column-list" *Cause: A REFERENCES clause in a CREATE/ALTER TABLE statement gives a column-list for which there is no matching unique or primary key constraint in the referenced table. *Action: Find the correct column names using the ALL_CONS_COLUMNS catalog view
--------------------------------------------------------------------------------------------------------------
Branch Table:
CREATE TABLE BRANCH (
BRANCHID NUMNER(4,0) NOT NULL, BRANCHNAME VARCHAR2 (30) NOT NULL, MANAGER_ID NUMBER(6,0), PLACEID NUMBER (4,0), FOREIGN KEY (MANAGER_ID, BRANCHID) REFERENCES STAFF(MANAGER_ID, BRANCHID); );
STAFF Table:
CREATE TABLE STAFF( STAFFID NUMBER(6,0) PRIMARY KEY NOT NULL, FNAME VARCHAR2(20), LNAME VARCHAR2(25) NOT NULL, SALARY NUMBER(8,2), MANAGER_ID NUMBER(6,0), BRANCHID NUMBER(4,0), FOREIGN KEY (BRANCHID, MANAGER_ID) REFERENCES BRANCH(BRANCHID, MANAGER_ID));
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started