Skip site navigation (1) Skip section navigation (2)

Re: surrogate vs natural primary keys

From: Seb <spluque(at)gmail(dot)com>
To: pgsql-sql(at)postgresql(dot)org
Subject: Re: surrogate vs natural primary keys
Date: 2008-09-17 13:20:58
Message-ID: 87abe6vrgl.fsf@patagonia.sebmags.homelinux.org (view raw or flat)
Thread:
Lists: pgsql-sql
On Tue, 16 Sep 2008 20:34:51 -0600,
"Scott Marlowe" <scott(dot)marlowe(at)gmail(dot)com> wrote:

[...]

> create table t2 (
>     d1 varchar(200),
>     d2 int8,
>     d3 varchar(1000),
>     foreign key t2_fk references t1(c1,c2) );

Thanks Scott, I guess you meant:

CREATE TABLE t2 (
    d1 varchar(200),
    d2 int8,
    d3 varchar(1000),
    PRIMARY KEY (d1, d2)
    FOREIGN KEY (d1, d2) REFERENCES t1(c1, c2) );

But this makes it difficult to work with t2 because it has 2 fields that
are the same as in t1.  Isn't it better to just use a surrogate key and
use a single field in t2, thereby avoiding repeating multiple pieces of
information?


Thanks,

-- 
Seb


In response to

Responses

pgsql-sql by date

Next:From: Scott MarloweDate: 2008-09-17 14:45:30
Subject: Re: surrogate vs natural primary keys
Previous:From: Bart DegryseDate: 2008-09-17 11:01:45
Subject: Re: May I have an assistance on CREATE TABLE Command

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group