Home » SQL & PL/SQL » SQL & PL/SQL » Composite Foreign key
Composite Foreign key [message #18907] Wed, 20 February 2002 19:14 Go to next message
Tariq Zia lakho
Messages: 8
Registered: February 2002
Junior Member
Hye.
I want to create a foeign compsite key, where i have been creeated Composite primary key on three columns.
column name are as under
1.inv_no
2.reg_no
2.season
when i make composite key with this command an error generated by oracle.
plz give me advice or session
i will be very thankful to u.

ALTER TABLE INV_DTL
ADD CONSTRAINTS INV_NO_REF_NO_SEASON_FK FOREIGN KEY INV_NO,REF_NO,SEASON)
REFERENCES INV_MST

Error return from oracle.
ERROR at line 2:
ORA-02298: cannot validate (UREA.INV_NO_REF_NO_SEASON_FK) - parent keys not found
Re: Composite Foreign key [message #18909 is a reply to message #18907] Wed, 20 February 2002 19:32 Go to previous messageGo to next message
Todd Barry
Messages: 4819
Registered: August 2001
Senior Member
There are row(s) in your detail table which do not have a corresponding row in the master (header) table based on those three columns.

You will need to identify and delete/correct those rows. Here is how to identify them:

select *
  from inv_dtl d
 where not exists
  (select null
     from inv_mst m
    where m.inv_no = d.inv_no
      and m.ref_no = d.ref_no
      and m.season = d.season);
Re: Composite Foreign key [message #18944 is a reply to message #18907] Thu, 21 February 2002 23:23 Go to previous messageGo to next message
maithili
Messages: 2
Registered: February 2002
Junior Member
hey,

ALTER TABLE INV_DTL
ADD CONSTRAINTS inv_ref_sea_fk FOREIGN KEY (INV_NO,REF_NO,SEASON)
REFERENCES INV_MST(INV_NO,REF_NO,SEASON);
Re: Composite Foreign key [message #21401 is a reply to message #18907] Thu, 01 August 2002 07:13 Go to previous message
Bruno
Messages: 12
Registered: May 2002
Junior Member
got similar problem. Using the select statement I could identify 33 records. But when changing SELECT into DELETE results in ORA-00903: invalid table name !!
How is this possible ??
Thanks.
Previous Topic: ORA-6502 error
Next Topic: checking Varchar is Numeric
Goto Forum:
  


Current Time: Thu Apr 25 23:40:17 CDT 2024