pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: pierre@desertmoon.com
To: lynch@lscorp.com
Cc: Colin@desertmoon.com, Dick@desertmoon.com, <cdick@mail.ocis.net>
Cc: pgsql-sql@postgreSQL.org
Subject: Re: [SQL] Creating table with unique key.
Date: 6 Aug 1998 08:39:53 -0700
Message-ID: <19980806153953.14992.qmail@desertmoon.com> (raw)
In-Reply-To: <v02140b58b1ee55140c5b@[207.152.64.133]>

> 
> At 2:49 PM 8/5/98, Colin Dick wrote:
> >> > CREATE TABLE cliente (
> >> >         name    varchar(100) UNIQUE NOT NULL,
> >> >         username        varchar(8) NOT NULL ,
> >> >         key     int4 NOT NULL DEFAULT nextval('key_s') PRIMARY KEY,
> 
> There should be no comma (,) in the last field description.
> 
> >> >         );
> >
> >Hi this is from a previous post regarding auto-incrementing.  I have that
> >part working, now I am trying to create a table with a field which will
> >not be null and will be unique to the rest of table.  Is this possible and
> >what is the correct syntax.  I have tried and receeved the following:
> >
> 
> CREATE TABLE cust (
>   FileNumber int4 unique not null,
>   CompName varchar(50),
>   FirstName varchar(50),
>   LastName varchar(50),
>   BirthDate varchar(8),
>   Suite varchar(5),
>   Address varchar(50),
>   City varchar(20),
>   Province varchar(20),
>   PostalCode varchar(7),
>   Email varchar(50),
>   HomePhone varchar(14),
>   WorkPhone varchar(14),
>   FaxPhone varchar(14));

I use the UNIQUE keyword on an index to force a uniqueness in a table field.

eg.

create unique index pindex_id 
on product using btree (product_id);


Where the field product_id is defined in the table as being not allowing a
null value.  This works like a charm....

-=pierre



view thread (6+ messages)

Message-ID: <19980806153953.14992.qmail@desertmoon.com>
Permalink:  ../19980806153953.14992.qmail@desertmoon.com/
Also on:    postgresql.org/message-id/19980806153953.14992.qmail@desertmoon.com

 · 

reply

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 from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-sql@postgresql.org
  Cc: pierre@desertmoon.com, lynch@lscorp.com, cdick@mail.ocis.net
  Subject: Re: [SQL] Creating table with unique key.
  In-Reply-To: <19980806153953.14992.qmail@desertmoon.com>
  References: <v02140b58b1ee55140c5b@[207.152.64.133]> <19980806153953.14992.qmail@desertmoon.com>

* 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