X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id 855C6D93C7 for ; Fri, 14 Oct 2005 09:42:55 -0300 (ADT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 78714-05 for ; Fri, 14 Oct 2005 12:42:50 +0000 (GMT) Received: from kraid.nerim.net (smtp-105-friday.nerim.net [62.4.16.105]) by svr1.postgresql.org (Postfix) with ESMTP id DB462D91C2 for ; Fri, 14 Oct 2005 09:42:52 -0300 (ADT) Received: from jobmare.clarisys.lan (claridsl512.net1.nerim.net [213.41.148.137]) by kraid.nerim.net (Postfix) with ESMTP id 47EFD40F67; Fri, 14 Oct 2005 14:42:55 +0200 (CEST) Received: from day by jobmare.clarisys.lan with local (Exim 4.52) id 1EQOuM-0001uP-FP; Fri, 14 Oct 2005 14:43:34 +0200 Date: Fri, 14 Oct 2005 14:43:34 +0200 From: David Pradier To: Russell Simpkins Cc: pgsql-sql@postgresql.org Subject: Re: Design problem : using the same primary keys for inherited objects. Message-ID: <20051014124334.GC19930@clarisys.fr> References: <20051014091829.GB19930@clarisys.fr> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.9i X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.05 required=5 tests=[FORGED_RCVD_HELO=0.05] X-Spam-Level: X-Archive-Number: 200510/160 X-Sequence-Number: 23013 > Most of the inheritance i've seen done in databases retain the parent primary as a foreign key and a primary key. That being said, only you and your team can decide if more than one object will extend a base class. If you were doing something more like this > person -> sweepstakes entry > to model a sweepsakes entry is a person, and you allow a person to enter a sweepstakes more than once, but to enter a contest the user must provide a unique email address, then you could not just use a foreign key as the primary key in sweepstakes, since the primary key would disallow multiple entries in sweepstakes entry, you would then use a serial data type in both person and sweepstakes along with the foriegn key in sweepstakes from person. > The answer depends on the need. Hope that helps. Thanks Russ, but well... It doesn't help me a lot. Our needs seem to allow that we use an id as primary key and foreign key at the same time. What i fear more is that it be against a good database design practice, because leading to potential problems. I give a clearer example : CREATE TABLE actor ( id_actor serial PRIMARY KEY, arg1 type1, arg2 type2 ) CREATE TABLE person ( id_person INTEGER PRIMARY KEY REFERENCES actor, arg3 type3, arg4 type4 ) Don't you think it is a BAD design ? If it isn't, well, it will expand my database practices. David -- David Pradier -- Directeur Technique de Clarisys Informatique -- Chef de projet logiciels libres / open-source