Re: Auto Increment

From: Cory Wright <corz(at)southcarrollton(dot)net>
To: <pgsql-sql(at)postgresql(dot)org>
Subject: Re: Auto Increment
Date: 2001-10-23 15:24:02
Message-ID: Pine.LNX.4.33L2.0110231123090.15512-100000@napoleon.southcarrollton.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

Try using SERIAL:

CREATE TABLE mytable (
MYID SERIAL,
name TEXT
);

It will auto create the sequences for you.

Cory Wright
corz(at)southcarrollton(dot)net
http://www.southcarrollton.net/
On Mon, 22 Oct 2001, Arian Prins wrote:

> On Mon, 22 Oct 2001 12:06:21 +0530, "Mayuresh Kadu"
> <mayureshk(at)aftek(dot)com> wrote:
>
> >hi all,
> >
> >could anyone tell me how to make a primary key to AUTO INCREMENT. The
> >document is not exactly very explainatory about it :)
> >
> >Thankx in advance ...
> >
> >
> >
> >Mayuresh
> >
> >
>
> Try first creating a sequence and then using the sequence as a default
> value in your table:
>
>
> -- STEP 1: create sequence
> create sequence mytableid_seq;
>
> -- STEP 2: create table
> create table mytable (
> id int default nextval ('mytableid_seq'),
> anyvalue varchar
> primary key (id));
>
> ---------------------------(end of broadcast)---------------------------
> TIP 3: if posting/reading through Usenet, please send an appropriate
> subscribe-nomail command to majordomo(at)postgresql(dot)org so that your
> message can get through to the mailing list cleanly
>

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Aasmund Midttun Godal 2001-10-23 16:31:12 Re: PL/pgSQL triggers ON INSERT OR UPDATE
Previous Message Troy 2001-10-23 15:03:05 Re: Diferent databases on same query...