General SQL Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsDatabasesGeneral SQL Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old June 29th, 2005, 12:04 PM
kbr kbr is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jun 2005
Posts: 3 kbr User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 39 m 46 sec
Reputation Power: 0
help needed with a foreign key error

Hi all,

I'm new to sql and started practicing creating tables with primary and foreign key constraints.I'm stuck with an error.I have created two tables category_header and route_header.cat_code is the primary key in category_header and cat_code is the foreign key in the table route_header.I started entering values for both the tables.First one created without any problem but the second table is not taking the values.Please take a look at the following code and let me know what went wrong:

SQL> desc category_header;
Name Null? Type
----------------------------------------- -------- ----------------------------
CAT_CODE NOT NULL NUMBER(5)
CAT_DESC VARCHAR2(15)

SQL> desc route_header;
Name Null? Type
----------------------------------------- -------- ----------------------------
ROUTE_ID NOT NULL NUMBER(5)
CAT_CODE NUMBER(5)
ROUTE_NO NOT NULL NUMBER(2)
ORIGIN NOT NULL VARCHAR2(15)
DESTINATION NOT NULL VARCHAR2(15)
FARE NOT NULL NUMBER(2)
DISTANCE NOT NULL NUMBER(3)
CAPACITY NOT NULL NUMBER(2)

SQL> select * from category_header;

CAT_CODE CAT_DESC
---------- ---------------
1 superdeluxe
2 deluxe
3 super fast
4 normal

SQL> select * from route_header;

no rows selected

SQL> insert into route_header values(&route_id, &cat_code, &route_no, '&origin', '&destination', &fa
re,&distance,&capacity);
Enter value for route_id: 101
Enter value for cat_code: 33
Enter value for route_no: 01
Enter value for origin: houston
Enter value for destination: dallas
Enter value for fare: 35
Enter value for distance: 250
Enter value for capacity: 50
old 1: insert into route_header values(&route_id, &cat_code, &route_no, '&origin', '&destination',
new 1: insert into route_header values(101, 33, 01, 'houston', 'dallas', 35,250,50)
insert into route_header values(101, 33, 01, 'houston', 'dallas', 35,250,50)
*
ERROR at line 1:
ORA-02291: integrity constraint (SCOTT.FK_CAT_CODE) violated - parent key not
found

Reply With Quote
  #2  
Old June 29th, 2005, 01:26 PM
Madpawn Madpawn is offline
My beat is correct.
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Dec 2004
Posts: 339 Madpawn User rank is Private First Class (20 - 50 Reputation Level)Madpawn User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 2 Days 22 h 3 m 33 sec
Reputation Power: 4
Should the cat_code you're trying to enter be 3 instead of 33?
__________________
"A pawn is the most important piece on the chessboard -- to a pawn"


Reply With Quote
  #3  
Old June 29th, 2005, 06:58 PM
kbr kbr is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jun 2005
Posts: 3 kbr User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 39 m 46 sec
Reputation Power: 0
Quote:
Originally Posted by Madpawn
Should the cat_code you're trying to enter be 3 instead of 33?


Oh, I'm sorry.I have corrected that mistake.But still I'm getting the same error. see the following output:

insert into route_header values(&route_id, &cat_code, &route_no, '&origin', '&destination', &fa
re,&distance,&capacity);
Enter value for route_id: 101
Enter value for route_no: 33
Enter value for cat_code: 1
Enter value for origin: houston
Enter value for destination: dallas
Enter value for fare: 35
Enter value for distance: 250
Enter value for capacity: 50
old 1: insert into route_header values(&route_id, &cat_code, &route_no, '&origin', '&destination',
new 1: insert into route_header values(101, 33, 01, 'houston', 'dallas', 35,250,50)
insert into route_header values(101, 33, 1, 'houston', 'dallas', 35,250,50)
*
ERROR at line 1:
ORA-02291: integrity constraint (SCOTT.FK_CAT_CODE) violated - parent key not
found

Reply With Quote
  #4  
Old June 29th, 2005, 07:21 PM
Madpawn Madpawn is offline
My beat is correct.
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Dec 2004
Posts: 339 Madpawn User rank is Private First Class (20 - 50 Reputation Level)Madpawn User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 2 Days 22 h 3 m 33 sec
Reputation Power: 4
It looks like your info's not lining up -- you've still got 33 in the cat_code position and 1 in the route_no. So if there's no 33 cat_code in category_header, you can't add a row with a cat_code of 33 into route_header.

Reply With Quote
  #5  
Old June 29th, 2005, 08:46 PM
kbr kbr is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jun 2005
Posts: 3 kbr User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 39 m 46 sec
Reputation Power: 0
Quote:
Originally Posted by Madpawn
It looks like your info's not lining up -- you've still got 33 in the cat_code position and 1 in the route_no. So if there's no 33 cat_code in category_header, you can't add a row with a cat_code of 33 into route_header.


Hi,

Thanks for the reply.I have created the first row after lot of stupid mistakes.As you mentioned, I'm not entering values correctly.It is a simple mistake but I thought I did something wrong while creating the first table.Thanks again..

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsDatabasesGeneral SQL Development > help needed with a foreign key error


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 6 hosted by Hostway
Stay green...Green IT