Oracle Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsDatabasesOracle Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old February 14th, 2005, 05:20 PM
mikestan21 mikestan21 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2003
Posts: 21 mikestan21 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 52 m 7 sec
Reputation Power: 0
(quick)constraint syntax question...

hi,
I'm trying to add a constraint for a primary key and a foreign key to the same table, but can't quite figure out the syntax? I can get the PK to work fine by itself, but when I add the FK in like below, it gives me errors?
Any help is appreciated,
-stan

Code:
create table image_number
(
number               int NOT NULL,
image_id                int NOT NULL,
CONSTRAINT be_num_pk PRIMARY KEY (number),
fk_image_id FOREIGN KEY (image_id) REFERENCES image(image_id)
);

Reply With Quote
  #2  
Old February 15th, 2005, 03:30 AM
swampBoogie swampBoogie is offline
Contributing User
Dev Shed Intermediate (1500 - 1999 posts)
 
Join Date: Jan 2003
Location: Paris Uppland
Posts: 1,784 swampBoogie User rank is Sergeant Major (2000 - 5000 Reputation Level)swampBoogie User rank is Sergeant Major (2000 - 5000 Reputation Level)swampBoogie User rank is Sergeant Major (2000 - 5000 Reputation Level)swampBoogie User rank is Sergeant Major (2000 - 5000 Reputation Level)swampBoogie User rank is Sergeant Major (2000 - 5000 Reputation Level)swampBoogie User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 2 Weeks 4 Days 21 h 42 m 49 sec
Reputation Power: 37
Code:
create table image_number
(
number               int NOT NULL,
image_id                int NOT NULL,
CONSTRAINT be_num_pk PRIMARY KEY (number),
CONSTRAINT fk_image_id FOREIGN KEY (image_id) REFERENCES image(image_id)
);

Reply With Quote
  #3  
Old February 15th, 2005, 10:36 AM
mikestan21 mikestan21 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2003
Posts: 21 mikestan21 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 52 m 7 sec
Reputation Power: 0
swamp,
thanks for the help, I had tried that earlier, but it also gave me an error:

Code:
ORA-02449: unique/primary keys in table referenced by foreign keys

ORA-00955: name is already used by an existing object


Is this something that has to do with cascading delete? I have a drop table at the top of my script, is there something I should add to it?
Code:
drop table image;
drop table image_be_number;
drop table image_jpg;
drop table image_request;
drop table user_name;
drop table role;
drop table source;
drop table department;


-stan


Quote:
Originally Posted by swampBoogie
Code:
create table image_number
(
number               int NOT NULL,
image_id                int NOT NULL,
CONSTRAINT be_num_pk PRIMARY KEY (number),
CONSTRAINT fk_image_id FOREIGN KEY (image_id) REFERENCES image(image_id)
);

Reply With Quote
  #4  
Old February 15th, 2005, 10:51 AM
mikestan21 mikestan21 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2003
Posts: 21 mikestan21 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 52 m 7 sec
Reputation Power: 0
swamp,
would this be close?

Code:
CONSTRAINT be_num_pk PRIMARY KEY (be_number),
CONSTRAINT fk_image_id FOREIGN KEY (image_id) REFERENCES image(image_id) ONDELETE CASCADE


it still gives me a 942 and 922 error?




Quote:
Originally Posted by mikestan21
swamp,
thanks for the help, I had tried that earlier, but it also gave me an error:

Code:
ORA-02449: unique/primary keys in table referenced by foreign keys

ORA-00955: name is already used by an existing object


Is this something that has to do with cascading delete? I have a drop table at the top of my script, is there something I should add to it?
Code:
drop table image;
drop table image_be_number;
drop table image_jpg;
drop table image_request;
drop table user_name;
drop table role;
drop table source;
drop table department;


-stan

Reply With Quote
  #5  
Old February 16th, 2005, 03:25 AM
swampBoogie swampBoogie is offline
Contributing User
Dev Shed Intermediate (1500 - 1999 posts)
 
Join Date: Jan 2003
Location: Paris Uppland
Posts: 1,784 swampBoogie User rank is Sergeant Major (2000 - 5000 Reputation Level)swampBoogie User rank is Sergeant Major (2000 - 5000 Reputation Level)swampBoogie User rank is Sergeant Major (2000 - 5000 Reputation Level)swampBoogie User rank is Sergeant Major (2000 - 5000 Reputation Level)swampBoogie User rank is Sergeant Major (2000 - 5000 Reputation Level)swampBoogie User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 2 Weeks 4 Days 21 h 42 m 49 sec
Reputation Power: 37
Constraint names must be unique within a schema. So either be_num_pk or fk_image_id has already been used as a constraint name within the schema.

Reply With Quote
Reply

Viewing: Dev Shed ForumsDatabasesOracle Development > (quick)constraint syntax question...


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