Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
Home -> Community -> Usenet -> c.d.o.server -> Re: Foriegn Key Question
Wally wrote:
> All,
>
> Database Version: 10.2.0.1
> OS: XP Pro
>
> I have a question about Foriegn Keys. Forgive me if this has been
> answered before.
>
> I have three tables which are
>
> subject with primary_key subject_id (VARCHAR2(10)),
> contact with primary_key contact_id (VARCHAR2(10)),
> &
> address with primary_key address_id (VARCHAR2(10))
>
> The address table has another column called owner_id (VARCHAR2(10))
> where the owner_id could be the subject_id or the contact_id, because
> either the subject or the contact could have an address. Currently the
> constraint is being maintained through pl/sql code.
>
> I know that I can have one foriegn key where the address.owner_id is
> linked to the subject.subject_id, or one foriegn key where the
> address.owner_id is linked to the contact.contact_id, but not both.
> Please correct me if I am wrong.
>
> This will not work since the owner_id can be either the subject_id or
> the contact_id.
>
> Is there a way other than a database trigger or pl/sql code where I can
> define the above relationship in the database.
>
> Thanks for your help.
Foreign keys can (and should) be declared at database level.
http://download-uk.oracle.com/docs/cd/B19306_01/server.102/b14220/data_int.htm#sthref3085
HTH -g Received on Fri Aug 11 2006 - 09:31:27 CDT