X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 2A5C39DCA03 for ; Fri, 24 Mar 2006 12:52:38 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 76468-03 for ; Fri, 24 Mar 2006 12:52:36 -0400 (AST) X-Greylist: domain auto-whitelisted by SQLgrey- Received: from nproxy.gmail.com (nproxy.gmail.com [64.233.182.201]) by postgresql.org (Postfix) with ESMTP id E013E9DCCB5 for ; Fri, 24 Mar 2006 12:52:35 -0400 (AST) Received: by nproxy.gmail.com with SMTP id l24so257772nfc for ; Fri, 24 Mar 2006 08:52:32 -0800 (PST) DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com; h=received:message-id:date:from:to:subject:mime-version:content-type:content-transfer-encoding:content-disposition; b=BPiI80a3GyhJjr6WKGT356xqjM3JJZCuY7xJU+n5MAFUyvsnERQQ6IXj0HC4NW0GmAHzhH/NhajcaCl3x1dpGFhTLKwl6EMpL4Ir2jInT22pC8/cLJm02T25+gKAv/hLhIjp7BBkS4C54q4mitzMLHI7wwH9xLqDz7c2eGJa4qg= Received: by 10.49.81.12 with SMTP id i12mr343351nfl; Fri, 24 Mar 2006 08:52:31 -0800 (PST) Received: by 10.49.17.3 with HTTP; Fri, 24 Mar 2006 08:52:31 -0800 (PST) Message-ID: <226d83de0603240852q54af3512odfce218d69718c8b@mail.gmail.com> Date: Fri, 24 Mar 2006 11:52:31 -0500 From: "Todd Kennedy" To: pgsql-sql@postgresql.org Subject: Question about One to Many relationships MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Content-Disposition: inline X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0 required=5 tests=[none] X-Spam-Score: 0 X-Spam-Level: X-Archive-Number: 200603/379 X-Sequence-Number: 24725 Hi, This should be a simple idea, but I've been going back and forth on it with various people in my tech group. So I've got two tables, one for albums and one for bands, for simplicity's sake, they look like this: CREATE TABLE bands ( id serial PRIMARY KEY, name varchar(64) NOT NULL CHECK( name <> ''), UNIQUE(name) ); CREATE TABLE albums ( id serial PRIMARY KEY, name varchar(128) NOT NULL CHECK( name <> '') ); And I want to link the band to the album, but, if the album is a compilation it'll be linked to multiple band.ids, so i can't just add a column like: band_id integer REFERENCES band (id) to the albums table, othewise i'd have to duplicate the albums in the table (one record for each band associated with an album). I thought a lookup table would be appropriate here, so like: CREATE TABLE bands_on_album ( id serial PRIMARY KEY, band_id integer REFERENCES band (id), album_id integer REFERENCES albums (id) ) but i'm being told this is "wrong" I feel like this is the accurate way to do this, does any one have experience on this matter? Thanks! Todd