patternMinor
ORA-02270: no matching unique or primary key for this column-list
Viewed 0 times
thisuniqueprimarycolumnorafor02270listmatchingkey
Problem
I getting an error report of:
Error report -
SQL Error: ORA-02270: 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
Can I know why?
parent table
child table
I keep nationality and fingerprint as duplicate because it will be time consuming in verifying based on all information stored in studentinfo, therefore by breaking into individual class will be easier and faster. like for the table STUDENTINFO consist 1 million record, in table bit_2015_sep_cit4114_fyp_G_ will only have 40 records. I keep the nationality column because I have 1 more column in my table structure which is visa renewal which calculated based on the value of nationality in the table.
Error report -
SQL Error: ORA-02270: no matching unique or primary key for this column-list
- 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
Can I know why?
parent table
CREATE TABLE STUDENTINFO
(
Student_ID VARCHAR2 (10) PRIMARY KEY,
Full_Name VARCHAR2 (50) NOT NULL,
Contact_Number NUMBER (15)NOT NULL,
Address VARCHAR2 (50) NOT NULL,
Nationality VARCHAR2 (15) NOT NULL,
IC_PassportNo VARCHAR2 (15) NOT NULL,
Programme VARCHAR (75) NOT NULL,
Email_Address VARCHAR2 (50) NOT NULL REFERENCES USERNAMEPASSWORD(Username),
Parents_Number NUMBER (15)NOT NULL,
Fingerprint_Template clob
);child table
create table bit_2015_sep_cit4114_fyp_G_
(
Student_ID VARCHAR2 (10) PRIMARY KEY REFERENCES STUDENTINFO(Student_ID),
Full_Name VARCHAR2 (50) NOT NULL REFERENCES STUDENTINFO(Full_Name),
Nationality VARCHAR2 (15) NOT NULL REFERENCES STUDENTINFO(Nationality),
Fingerprint_Template CLOB NOT NULL REFERENCES STUDENTINFO(Fingerprint_Template),
"23/10/2015" VARCHAR2 (15) not null,
);I keep nationality and fingerprint as duplicate because it will be time consuming in verifying based on all information stored in studentinfo, therefore by breaking into individual class will be easier and faster. like for the table STUDENTINFO consist 1 million record, in table bit_2015_sep_cit4114_fyp_G_ will only have 40 records. I keep the nationality column because I have 1 more column in my table structure which is visa renewal which calculated based on the value of nationality in the table.
Solution
Fullname etc. are not declared as unique in the parent table, and therefore you can't reference them from the child table.
Why do you need to duplicate these columns in the child table?
EDIT:
Locking at you child table you say that:
What this means is that there must be a unique row in STUDENTINFO with this fullname. I.e. you need to declare that table:
I doubt that full_name is unique which means you cant declare a foreign key against this column.
You seem to assume that there will be performance problems later on and therefore you de-normalize your database. IMO this is a big mistake, start with a normalized database and de-normalize only when there is reason to do so.
If you insist on de-normalizing you can use a trick like:
Since Student_ID is unique it follows that Student_ID, Full_Name, Nationality must also be unique. I excluded Fingerprint_Template since I doubt that this can be used in foreign keys (not sure though, if it can you can add it)
);
But as mentioned, start with a normalized design and see if that works
Why do you need to duplicate these columns in the child table?
EDIT:
Locking at you child table you say that:
create table bit_2015_sep_cit4114_fyp_G_
( ...
, Full_Name VARCHAR2 (50) NOT NULL
REFERENCES STUDENTINFO(Full_Name)What this means is that there must be a unique row in STUDENTINFO with this fullname. I.e. you need to declare that table:
CREATE TABLE STUDENTINFO
( ...
, Full_Name VARCHAR2 (50) NOT NULL
UNIQUE,I doubt that full_name is unique which means you cant declare a foreign key against this column.
You seem to assume that there will be performance problems later on and therefore you de-normalize your database. IMO this is a big mistake, start with a normalized database and de-normalize only when there is reason to do so.
If you insist on de-normalizing you can use a trick like:
CREATE TABLE STUDENTINFO
( Student_ID VARCHAR2 (10) PRIMARY KEY
, Full_Name VARCHAR2 (50) NOT NULL
, Contact_Number NUMBER (15)NOT NULL
, Address VARCHAR2 (50) NOT NULL
, Nationality VARCHAR2 (15) NOT NULL
...
, constraint AK1_STUDENTINFO unique (Student_ID, Full_Name, Nationality)Since Student_ID is unique it follows that Student_ID, Full_Name, Nationality must also be unique. I excluded Fingerprint_Template since I doubt that this can be used in foreign keys (not sure though, if it can you can add it)
create table bit_2015_sep_cit4114_fyp_G_
( Student_ID VARCHAR2 (10) PRIMARY KEY
, Full_Name VARCHAR2 (50) NOT NULL
, Nationality VARCHAR2 (15) NOT NULL
...
, constraint fk_studentinfo foreign key (Student_ID, Full_Name, Nationality)
references studentinfo (Student_ID, Full_Name, Nationality));
But as mentioned, start with a normalized design and see if that works
Code Snippets
create table bit_2015_sep_cit4114_fyp_G_
( ...
, Full_Name VARCHAR2 (50) NOT NULL
REFERENCES STUDENTINFO(Full_Name)CREATE TABLE STUDENTINFO
( ...
, Full_Name VARCHAR2 (50) NOT NULL
UNIQUE,CREATE TABLE STUDENTINFO
( Student_ID VARCHAR2 (10) PRIMARY KEY
, Full_Name VARCHAR2 (50) NOT NULL
, Contact_Number NUMBER (15)NOT NULL
, Address VARCHAR2 (50) NOT NULL
, Nationality VARCHAR2 (15) NOT NULL
...
, constraint AK1_STUDENTINFO unique (Student_ID, Full_Name, Nationality)create table bit_2015_sep_cit4114_fyp_G_
( Student_ID VARCHAR2 (10) PRIMARY KEY
, Full_Name VARCHAR2 (50) NOT NULL
, Nationality VARCHAR2 (15) NOT NULL
...
, constraint fk_studentinfo foreign key (Student_ID, Full_Name, Nationality)
references studentinfo (Student_ID, Full_Name, Nationality)Context
StackExchange Database Administrators Q#130659, answer score: 6
Revisions (0)
No revisions yet.