Question

I am having trouble with mapping things on separate tables of data. There will be tables for DEPARTMENT_LOCATIONS, DEPARTMENT, EMPLOYEE, and PROJECT. So far all of the tables are created other that PROJECT, because I am receiving the error message for the title of my question.

Below is the information that I used to create the tables that were created without errors:

EMPLOYEE Table:

CREATE TABLE EMPLOYEE
(FNAME VARCHAR(25) NOT NULL,
MINIT CHAR(1),
LNAME VARCHAR(25) NOT NULL,
SSN NUMBER(10) NOT NULL,
BDATE DATE NOT NULL,
ADDRESS VARCHAR(30) NOT NULL,
SEX CHAR(1) NOT NULL,
SALARY DECIMAL(6,2) NOT NULL,
SUPERSSN NUMBER(10),
DNO NUMBER (1) NOT NULL,
PRIMARY KEY (SSN),
FOREIGN KEY (DNO) REFERENCES DEPT_LOCATIONS(DNUMBER));

DEPARTMENT_LOCATIONS Table:

CREATE TABLE DEPT_LOCATIONS
(DNUMBER NUMBER(1) NOT NULL,
DLOCATION VARCHAR(25) NOT NULL,
PRIMARY KEY (DNUMBER));

DEPARTMENT Table:

CREATE TABLE DEPARTMENT
(DNUMBER NUMBER(1) NOT NULL,
DNAME VARCHAR(25) NOT NULL,
MGRSTARTDATE DATE NOT NULL,
MGRSSN NUMBER(10) NOT NULL,
PRIMARY KEY (DNUMBER),
FOREIGN KEY (DNUMBER) REFERENCES DEPT_LOCATIONS(DNUMBER),
FOREIGN KEY (MGRSSN) REFERENCES EMPLOYEE(SSN));

Now when I enter the following information for the PROJECT Table, I receive the error message "ORA-02270: no matching unique or primary key for this column-list.)

CREATE TABLE PROJECT
(PNUMBER NUMBER(2,1) NOT NULL PRIMARY KEY,
PNAME VARCHAR(25) NOT NULL,
PLOCATION VARCHAR(25) NOT NULL,
DNUM NUMBER(1) NOT NULL,
FOREIGN KEY (PLOCATION) REFERENCES DEPT_LOCATIONS(DLOCATION),
FOREIGN KEY (DNUM) REFERENCES DEPT_LOCATIONS(DNUMBER));

Why is this error occurring and what do I need to do to correct it? Thank you.

Était-ce utile?

La solution

You have to declare dlocation as unique, inorder to reference it in another table.

CREATE TABLE DEPT_LOCATIONS
(DNUMBER NUMBER(1) NOT NULL,
DLOCATION VARCHAR(25) UNIQUE,
PRIMARY KEY (DNUMBER));
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top