If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > ANSI SQL > problem with foreign keys

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 03-04-06, 10:27
unim unim is offline
Registered User
 
Join Date: Mar 2006
Posts: 2
problem with foreign keys

Hiya, I'm having a prob I'd really appreciate any help. I get the message 'ORA-02273: this unique/primary key is referenced by some foreign keys' every time i try these foreign keys. I read another post on something similar but still need some help.

For example I have 2 tables:

CREATE TABLE EQUIPMENT
(serialno varchar2(7) not null,
equip varchar2(30),
primary key (serialno) );

CREATE TABLE ROOMBOOKING
(bookingdate date not null,
sess char(1) not null,
roomno number(3) not null,
misc varchar2(30),
primary key (bookingdate, sess, roomno) ); <<SO COMPOSITE KEY HERE

Now I need to make foreign keys in another table to some of these columns but I keep getting there error. For example I've got a table called EQUIPMENTBOOKING that contains
sess, bookingdate, roomno, serialno

but I cant get the keys working.

ALTER TABLE EQUIPMENTBOOKING
add constraint fkey_room
foreign key (bookingdate, roomno, sess) references roombooking (bookingdate, roomno, sess) ;


tried one at a time

ALTER TABLE EQUIPMENTBOOKING
add constraint fkey_room
foreign key (bookingdate) references roombooking (bookingdate) ;

still get the error. And still havent put in the other table one yet, its roombooking thats causing the problem. Can one help?

thanks alot
Reply With Quote
  #2 (permalink)  
Old 03-04-06, 10:42
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,524
try specifying the FK columns in the same order as the PK columns

in fact you should be able simply to reference the table, and it will figure out the PK

ALTER TABLE EQUIPMENTBOOKING
add constraint fkey_room
foreign key (bookingdate, sess, roomno) references roombooking
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #3 (permalink)  
Old 03-05-06, 08:42
unim unim is offline
Registered User
 
Join Date: Mar 2006
Posts: 2
Aaah, thanks a lot. That fixed it up. Working now, thankyou.
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On