From: Bruno Wolff III <bruno@wolff.to>
To: Saad Saeed <saads@umich.edu>
Cc: pgsql-sql@postgresql.org
Subject: Re: Creating a foreign key on the Union of two tables
Date: Mon, 7 Apr 2003 11:50:30 -0500
Message-ID: <20030407165030.GA17741@wolff.to> (raw)
In-Reply-To: <a811aba0.0304061353.664e2263@posting.google.com>
References: <a811aba0.0304061353.664e2263@posting.google.com>
On Sun, Apr 06, 2003 at 14:53:50 -0700,
Saad Saeed <saads@umich.edu> wrote:
> I have 2 tables "A" and "B" in mySQL. They both have an attribute 'id'
> which is unique between the 2 tables. I want the union of these 2
> attributes to be a foreign key in a 3rd table "C". How do I specify
> this constraing in sql (mySQL) in table C? And for complex reasons I
> cannot merge the 2 tables A and B.
One way to do this is to have two foreign key references from C. One to
A and the other to B. To make sure just one of these is used, you can
use a constraint in C to make sure exactly one of the columns is null.
This technique doesn't need for the IDs in A and B to be unique accross
both tables.
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-sql@postgresql.org
Cc: bruno@wolff.to, saads@umich.edu
Subject: Re: Creating a foreign key on the Union of two tables
In-Reply-To: <20030407165030.GA17741@wolff.to>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox