LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 05-19-2004, 08:31 PM   #1
darkRoom
Member
 
Registered: Mar 2004
Location: Valencia, espaņa
Distribution: Slack, Gentoo, Custom
Posts: 162

Rep: Reputation: 30
Oracle SQL+


Hi
I'm using oracle i8 sql+ and i cant figure out the syntax to create a single foreign key to reference 2 constraints in different tables ie i need to combine the following 2 table alterations so they can be a single alteration or alternatively to create the key at table design time.

Code:
ALTER TABLE propetyForRent ADD FOREIGN KEY(OwnerNo) REFERENCES PrivateOwner(OwnerNo);
Code:
ALTER TABLE propetyForRent ADD FOREIGN KEY(OwnerNo) REFERENCES businessOwner(OwnerNo);
thanks
 
Old 05-20-2004, 03:18 PM   #2
vasudevadas
Member
 
Registered: Jul 2003
Location: Bedford, UK
Distribution: Slackware 11.0, LFS 6.1
Posts: 519

Rep: Reputation: 30
I don't think you can, dude. You're trying to say that propertyForRent.OwnerNo must exist in either PrivateOwner.OwnerNo or BusinessOwner.OwnerNo and I don't think you can do that.

AFAIK (and I should be ashamed if I don't know this, nearly 6 years as an Oracle developer and all) a foreign key constraint can reference only one primary key.

If you want this, I humbly suggest that your data model is wrong. Perhaps you should merge your BusinessOwner and PrivateOwner into a single table, with OwnerNo as its primary key, and an extra column to identify whether the owner is private or commercial. You could then use two views to simulate the BusinessOwner and PrivateOwner tables if you wished:

Code:
CREATE VIEW BusinessOwner AS SELECT * FROM Owner WHERE Type='BUSINESS';
CREATE VIEW PrivateOwner AS SELECT * FROM Owner WHERE Type='PRIVATE';
That might help you out.

Last edited by vasudevadas; 05-20-2004 at 03:21 PM.
 
Old 05-20-2004, 09:01 PM   #3
darkRoom
Member
 
Registered: Mar 2004
Location: Valencia, espaņa
Distribution: Slack, Gentoo, Custom
Posts: 162

Original Poster
Rep: Reputation: 30
Thanks for the reply and useful advice

Actually i'm following a diagram and table listing taken from a database book. I'm guessing that they must revise the structure later on and then implement it in the way you are suggesting.

In which case im doing ok
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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



Similar Threads
Thread Thread Starter Forum Replies Last Post
xhost + as user oracle not working, need to see oracle install GUI enzo250gto Linux - Software 2 02-11-2007 11:27 AM
Sql + Oracle Select If ???? smaida Programming 11 12-15-2004 08:13 PM
Oracle SQL IDE grayswander Linux - Software 4 12-05-2003 11:17 AM
Installation of PL/Sql Server Pages with Oracle on RH 7.3 akamol Linux - Software 0 07-04-2003 06:05 AM
SQL and Oracle Rutnut Linux - General 3 04-07-2002 12:39 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 09:51 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration