Received: from localhost (unknown [200.46.204.184]) by postgresql.org (Postfix) with ESMTP id 52A7D2E003C; Thu, 22 Nov 2007 09:46:10 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.184]) (amavisd-maia, port 10024) with ESMTP id 57267-06; Thu, 22 Nov 2007 09:45:59 -0400 (AST) Received: from pih-relay06.plus.net (pih-relay06.plus.net [212.159.14.133]) by postgresql.org (Postfix) with ESMTP id C60052E0032; Thu, 22 Nov 2007 09:46:06 -0400 (AST) Received: from [84.51.143.99] (helo=server3.office.archonet.com) by pih-relay06.plus.net with esmtp (Exim) id 1IvCNY-00005G-0p; Thu, 22 Nov 2007 13:46:04 +0000 Received: from [192.168.1.36] (dell36.office.archonet.com [192.168.1.36]) by server3.office.archonet.com (Postfix) with ESMTP id 7A395274062; Thu, 22 Nov 2007 13:46:03 +0000 (GMT) Message-ID: <4745881B.6010904@archonet.com> Date: Thu, 22 Nov 2007 13:46:03 +0000 From: Richard Huxton User-Agent: Thunderbird 2.0.0.9 (X11/20071031) MIME-Version: 1.0 To: Richard Broersma Jr CC: SQL Postgresql List , General PostgreSQL List Subject: Re: [SQL] Bad Schema Design or Useful Trick? References: <82640.215.qm@web31815.mail.mud.yahoo.com> In-Reply-To: <82640.215.qm@web31815.mail.mud.yahoo.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200711/1205 X-Sequence-Number: 124201 Richard Broersma Jr wrote: > Below I've included sample table definitions for a vertically > partitioned disjunctive table hierarchy. I wanted to point out the > use of the composite primary key declaration that is applied to two > columns that are clearly not a candidate key. However, using the > badly defined primary key allows for referential integrity to nicely > handle the de-normalization between the main table and sub tables > that is inherent with this type of data model. > > Would using a primary key in this manner be a decision that I will > regret in the long run? If so, can any explain why? > > The parent table is parts with the child table pumps and hardware. > > CREATE TABLE Parts ( part_nbr varchar( 100 ) UNIQUE NOT NULL, > part_type varchar( 20 ) NOT NULL, ... > PRIMARY KEY ( part_nbr, part_type ), ... So - what you're saying is that because part_type depends on part_nbr it shouldn't be part of the key, but because you want to search by part-type in the referencing tables it makes life easier. Will you regret this? Probably - I always seem to end regretting making short-cuts, although in this case I can't see any direct harm that could occur. I'd probably make (part_nbr) the pkey and have a separate unique constraint on (part_nbr,part_type) that I reference. That "feels" better , although I'm not sure it actually gains you anything. -- Richard Huxton Archonet Ltd