Re: Increment primary key

Поиск
Список
Период
Сортировка
От wsheldah@lexmark.com
Тема Re: Increment primary key
Дата
Msg-id 200204032044.PAA26920@interlock2.lexmark.com
обсуждение исходный текст
Ответ на Increment primary key  (impala <bhnnc@yahoo.co.uk>)
Список pgsql-general

The easiest way is to do it in the CREATE TABLE statement:
CREATE TABLE mytable (id SERIAL PRIMARY KEY, name text);

That will make id an integer, automatically create a separate SEQUENCE, and bind
id to that sequence so that it is incremented properly.
The online docs elaborate on this; look for CREATE SEQUENCE, CREATE TABLE, and
SERIAL.  Best of luck!

Wes




impala <bhnnc%yahoo.co.uk@interlock.lexmark.com> on 04/03/2002 01:58:32 PM

To:   pgsql-general%postgresql.org@interlock.lexmark.com
cc:    (bcc: Wesley Sheldahl/Lex/Lexmark)
Subject:  [GENERAL] Increment primary key


Hi

I created a table and the primary key must increment
automatically with e.g 1 each time I insert a new row.
How do I write the psql code to make this happen?

Nic

__________________________________________________
Do You Yahoo!?
Yahoo! Tax Center - online filing with TurboTax
http://taxes.yahoo.com/

---------------------------(end of broadcast)---------------------------
TIP 1: subscribe and unsubscribe commands go to majordomo@postgresql.org





В списке pgsql-general по дате отправления:

Предыдущее
От: impala
Дата:
Сообщение: Increment primary key
Следующее
От:
Дата:
Сообщение: Re: do foreign key checks lock parent table ?