X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (neptune.hub.org [200.46.204.2]) by svr1.postgresql.org (Postfix) with ESMTP id 4ABB3D1B45D for ; Mon, 12 Jan 2004 21:37:25 +0000 (GMT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (neptune.hub.org [200.46.204.2]) (amavisd-new, port 10024) with ESMTP id 72007-02 for ; Mon, 12 Jan 2004 17:36:56 -0400 (AST) Received: from amnet.co.cr (mail.amnet.co.cr [196.40.3.6]) by svr1.postgresql.org (Postfix) with ESMTP id 04C05D1B447 for ; Mon, 12 Jan 2004 17:36:54 -0400 (AST) Received: from [10.15.8.41] (HELO racsa.co.cr) by amnet.co.cr (CommuniGate Pro SMTP 4.1b6) with SMTP id 17749098 for pgsql-sql@postgresql.org; Mon, 12 Jan 2004 15:32:06 -0600 Message-ID: <40031373.5000305@racsa.co.cr> Date: Mon, 12 Jan 2004 15:36:51 -0600 From: katarn User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.5) Gecko/20031007 X-Accept-Language: en-us, en MIME-Version: 1.0 To: pgsql-sql@postgresql.org Subject: Re: Unique key field or serverl fks ? References: <400235D5.1050501@racsa.co.cr> <200401120952.53629.dev@archonet.com> In-Reply-To: <200401120952.53629.dev@archonet.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: by amavisd-new at postgresql.org X-Archive-Number: 200401/99 X-Sequence-Number: 16492 >>Hi, >> >>I would like to know opinions about which approach is better: >> >>Having a table with a field that works as a unique key, or having >>several fks that work as a combined key ( all the fks fields )? >> >> > >Depends on the particular situation, you'll need to give details of the tables >and their place in your system. > >There are two reasons I've seen given for using an artificial (substitute) >primary key: >1. It's "lighter" than several other fields (especially where they are text) >2. The natural primary key has meaning to the users, and the users will tend >to get it wrong. > >The second is probably the more persuasive - the first can definitely have >costs as well as benefits. > > > Ok, thanks for answering, example: Articles Table articleid Warehouses Table warehouseid Locations per warehouse Table warehouseid (fk) locationid description Articles Per warehouse warehouseid (fk) articleid (fk) locationid (fk) stock In the Articles per warehouse the "primary key" is the cominbation of 3 fks. Is that kind of situation acceptable or it could be better to have a unique primary key field in addition to the fks? This "gets worse" if another table has information binded to the articles per warehouse, it has to reference the 3 fks in addition to its own key fields. Thanks in advance, K.