RE: Unique or Primary Key? - Mailing list pgsql-general

From Joel Burton
Subject RE: Unique or Primary Key?
Date
Msg-id Pine.LNX.4.21.0105031648200.8245-100000@olympus.scw.org
Whole thread Raw
In response to RE: Unique or Primary Key?  ("Christian Marschalek" <cm@chello.at>)
List pgsql-general
> > Besides, I couldn't see much use in creating it as a primary
> > key.  How
> > would I ever reference it from another table?

If you're questioning how to use a multi-field primary key, it's easy...


create table p (id1 int not null, id2 int not null, primary key(id1,
id2));

create table c (id1 int, id2 int, foreign key (id1, id2) references p);

insert into p values (1,2);
insert into c values (1,1);
insert into c values (1,0);

ERROR:  <unnamed> referential integrity violation - key referenced from c
not found in p

--
Joel Burton   <jburton@scw.org>
Director of Information Systems, Support Center of Washington


pgsql-general by date:

Previous
From: Joel Burton
Date:
Subject: Metaphone function attachment
Next
From: "Mitch Vincent"
Date:
Subject: Re: Ideal hardware - OS Wars are silly.