pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
Re: create table with multiple unique fields
2+ messages / 2 participants
[nested] [flat]

* Re: create table with multiple unique fields
@ 2002-01-07 12:58 ` steve boyle <boylesa@dial.pipex.com>
  1 sibling, 0 replies; 2+ messages in thread

From: steve boyle @ 2002-01-07 12:58 UTC (permalink / raw)
  To: pgsql-sql

Karl,

you can either set the Primary key over all 3 fields to ensure uniquenes
i.e:

create table warehouse (
        warehouseno int4,
        location    varchar(3),
        productid   varchar(1),
        primary key (warehouseno, location, productid)
);

or define a unique index over the 3 fields after the table has been defined:

create table warehouse (
        warehouseno int4,
        location    varchar(3),
        productid   varchar(1)
);

create unique index idx on warehouse (warehouseno, location, productid);

The difference between the two methods is that NULLS are not allowed in
Primary Keys (method 1) but would be allowed using the unique index (method
2).

Hope it helps

Steve Boyle

"Karl Raven" <lcaasia@pd.jaring.my> wrote in message
news:a1agea$qap$1@news.tht.net...
>
> I'd like to create a table with 3 create unique fields :
>
> fields
> warehouseno,loc, productid, qty, qtyalllocated
>
> i'd like warehouseno,loc, productid to be unique..
> meaning
> 2000, ABC, X           - ok
> 2000,ABC,Y            -ok
> 2000,ABC,X            - reject
> 2000,BCD,X            - ok
>
> anyone knows how to do so?
>
> thanks
>
>





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

* Re: create table with multiple unique fields
@ 2002-01-13 08:23 ` elisabeth maniez <emaniez@caramail.com>
  1 sibling, 0 replies; 2+ messages in thread

From: elisabeth maniez @ 2002-01-13 08:23 UTC (permalink / raw)
  To: pgsql-sql

create table T1 ( c1  int4, c2  int4, c3  int4, c4  int4, c5  int5, primary
key  (c1,c2,c3) );

Elisabeth
"Karl Raven" <lcaasia@pd.jaring.my> a écrit dans le message news:
a1agea$qap$1@news.tht.net...
>
> I'd like to create a table with 3 create unique fields :
>
> fields
> warehouseno,loc, productid, qty, qtyalllocated
>
> i'd like warehouseno,loc, productid to be unique..
> meaning
> 2000, ABC, X           - ok
> 2000,ABC,Y            -ok
> 2000,ABC,X            - reject
> 2000,BCD,X            - ok
>
> anyone knows how to do so?
>
> thanks
>
>





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


end of thread, other threads:[~2002-01-13 08:23 UTC | newest]

Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2002-01-07 12:58 ` steve boyle <boylesa@dial.pipex.com>
2002-01-13 08:23 ` elisabeth maniez <emaniez@caramail.com>

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