Re: brain-teaser with CONSTRAINT - any SQL experts?

From: Oliver Elphick <olly(at)lfix(dot)co(dot)uk>
To: Miles Keaton <mileskeaton(at)gmail(dot)com>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: brain-teaser with CONSTRAINT - any SQL experts?
Date: 2005-10-09 06:24:51
Message-ID: 1128839091.6751.28.camel@linda.lfix.co.uk
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Sat, 2005-10-08 at 22:36 -0700, Miles Keaton wrote:
> ... both isbn and name MUST be in the table, and what I'm
> trying to do is put a CONSTRAINT on the table definition to protect
> against user error, by making sure that any entered isbn is only tied
> to one book-name in that table.

Create a separate table with the two columns name and isbn which are
that table's primary key; on the main table, create a foreign key to the
new table.

--
Oliver Elphick olly(at)lfix(dot)co(dot)uk
Isle of Wight http://www.lfix.co.uk/oliver
GPG: 1024D/A54310EA 92C8 39E7 280E 3631 3F0E 1EC0 5664 7A2F A543 10EA
========================================
Do you want to know God? http://www.lfix.co.uk/knowing_god.html

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message andrew 2005-10-09 06:48:01 Re: INSERT OR UPDATE?
Previous Message smorrey 2005-10-09 06:15:37 INSERT OR UPDATE?