Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Can not create Foreign Key ! help required urgently. 2

Status
Not open for further replies.

cyberdyne

Programmer
May 1, 2001
173
IN
Hello friends,

I am facing a a strange problem while creating Foreign Key.
My premary key is already created. Please see below I have given a screen shot. you will understand. Pls help me urgently.
------------------------------------------------------------

SQL> desc medorder;
Name Null? Type
------------------------------- -------- ----
ORDNO NOT NULL VARCHAR2(10)
ADDRESS VARCHAR2(100)
GOODSDELAT VARCHAR2(75)
COMMENTS VARCHAR2(150)
ADVANCE VARCHAR2(10)
MOP VARCHAR2(10)


SQL> SELECT CONSTRAINT_NAME,CONSTRAINT_TYPE,TABLE_NAME FROM USER_CONSTRAINTS
2 WHERE TABLE_NAME='MEDORDER';

CONSTRAINT_NAME C TABLE_NAME
--------------------- - ------------------------------
MEDO_PK P MEDORDER

SQL> DESC MEDORDERCHANGE;
Name Null? Type
------------------------------- -------- ----
ORDNO VARCHAR2(10)
TECH VARCHAR2(255)
COMM VARCHAR2(255)
ACTION VARCHAR2(255)
ADDRESS VARCHAR2(100)
ITEMCODE VARCHAR2(50)
QTY VARCHAR2(10)
AMT VARCHAR2(20)
SRNO NUMBER(4)
DT VARCHAR2(10)
DELADDRESS VARCHAR2(100)
YEAR VARCHAR2(10)


SQL> ALTER TABLE MEDORDERCHANGE
2 ADD(CONSTRAINT MEDOC_ORDNO_FK FOREIGN KEY(ORDNO) REFERENCES MEDORDER(ORDNO));
ALTER TABLE MEDORDERCHANGE
*
ERROR at line 1:
ORA-02298: cannot enable (SCOTT.MEDOC_ORDNO_FK) - parent keys not found

thanks in advance
you can contact me at cyberdyne@softhome.net
 
Your child table already contains records without matching values in the parent table. Clear/change them or add appropriate "parent" records to the parent table
 
To find the culprits, try:

SELECT ordno FROM meordechange
WHERE ordno NOT IN (SELECT ordno FROM meorder);

Once you have a parent for every child, your foreign key should be doable.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top