pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
Unique key field or serverl fks ?
3+ messages / 2 participants
[nested] [flat]

* Unique key field or serverl fks ?
@ 2004-01-12 05:51 katarn <katarn@racsa.co.cr>
  2004-01-12 09:52 ` Re: Unique key field or serverl fks ? Richard Huxton <dev@archonet.com>
  0 siblings, 1 reply; 3+ messages in thread

From: katarn @ 2004-01-12 05:51 UTC (permalink / raw)
  To: pgsql-sql

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 )?

Thanks in advance,

K.




^ permalink  raw  reply  [nested|flat] 3+ messages in thread

* Re: Unique key field or serverl fks ?
  2004-01-12 05:51 Unique key field or serverl fks ? katarn <katarn@racsa.co.cr>
@ 2004-01-12 09:52 ` Richard Huxton <dev@archonet.com>
  2004-01-12 21:36   ` Re: Unique key field or serverl fks ? katarn <katarn@racsa.co.cr>
  0 siblings, 1 reply; 3+ messages in thread

From: Richard Huxton @ 2004-01-12 09:52 UTC (permalink / raw)
  To: katarn <katarn@racsa.co.cr>; pgsql-sql

On Monday 12 January 2004 05:51, katarn wrote:
> 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.

-- 
  Richard Huxton
  Archonet Ltd



^ permalink  raw  reply  [nested|flat] 3+ messages in thread

* Re: Unique key field or serverl fks ?
  2004-01-12 05:51 Unique key field or serverl fks ? katarn <katarn@racsa.co.cr>
  2004-01-12 09:52 ` Re: Unique key field or serverl fks ? Richard Huxton <dev@archonet.com>
@ 2004-01-12 21:36   ` katarn <katarn@racsa.co.cr>
  0 siblings, 0 replies; 3+ messages in thread

From: katarn @ 2004-01-12 21:36 UTC (permalink / raw)
  To: pgsql-sql


>>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.




^ permalink  raw  reply  [nested|flat] 3+ messages in thread


end of thread, other threads:[~2004-01-12 21:36 UTC | newest]

Thread overview: 3+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2004-01-12 05:51 Unique key field or serverl fks ? katarn <katarn@racsa.co.cr>
2004-01-12 09:52 ` Richard Huxton <dev@archonet.com>
2004-01-12 21:36   ` katarn <katarn@racsa.co.cr>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox