Received: from davinci.ethosmedia.com (davinci.ethosmedia.com [209.10.40.250]) by mail.postgresql.org (8.11.1/8.11.1) with ESMTP id f1LGgKx00129 for ; Wed, 21 Feb 2001 11:42:21 -0500 (EST) (envelope-from josh@agliodbs.com) Received: from [207.172.28.154] (HELO agliodbs.com) by davinci.ethosmedia.com (CommuniGate Pro SMTP 3.3) with ESMTP id 1193262 for pgsql-sql@postgresql.org; Wed, 21 Feb 2001 08:42:12 -0800 Message-ID: <3A93EFDF.C4FC5689@agliodbs.com> Date: Wed, 21 Feb 2001 08:42:07 -0800 From: Josh Berkus Reply-To: josh@agliodbs.com Organization: Aglio Database Solutions X-Mailer: Mozilla 4.73 [en] (Win98; I) X-Accept-Language: en MIME-Version: 1.0 To: sqllist Subject: two tables - foreign keys referring to each other...] Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Archive-Number: 200102/322 X-Sequence-Number: 1518 Chris, > ..or generally: how do you create two crosslinked foreign keyed tables? > > hopefully an easy problem for the real professionals! No. The problem is: Why would you want to create two crosslinked foriegn-keyed tables? As an experienced SQL professional, this seems like a recipe for instant disaster to me. The purpose of a foriegn key is to enforce a parent-->child or data table<--reference list relationships, to prevent incomplete or erroneous records from being added. This requires the foriegn key relationship to be one-way. In fact, if you built your two-way foriegn keys (using ALTER TABLE), I think you might find that you can't add any records to either table. Certainly you won't be able to delete any. I once had an experience with a complex legacy data structure where I accidentally set up a circular foriegn key relationship (among 5 tables), and I had to re-build the database from scripts to fix it. If you're looking to set up a many-to-many relationship, then what you want is a linking table. However, I highly advise you to pick up a primer on database design (such as "Database Design for Mere Mortals") before proceeding any further, or you'll end up spending the next year paying for what you don't understand now. -Josh Berkus -- ______AGLIO DATABASE SOLUTIONS___________________________ Josh Berkus Complete information technology josh@agliodbs.com and data management solutions (415) 565-7293 for law firms, small businesses fax 621-2533 and non-profit organizations. San Francisco