From: steve boyle <boylesa@dial.pipex.com>
To: pgsql-sql@postgresql.org
Subject: Re: create table with multiple unique fields
Date: Mon, 7 Jan 2002 12:58:10 -0000
Message-ID: <a1c622$13qg$1@news.tht.net> (raw)
References: <a1agea$qap$1@news.tht.net>
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
>
>
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-sql@postgresql.org
Cc: boylesa@dial.pipex.com
Subject: Re: create table with multiple unique fields
In-Reply-To: <a1c622$13qg$1@news.tht.net>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
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