Re: [SQL] Unique Number KEY

Поиск
Список
Период
Сортировка
Искать
От
CIMPOESU Teodor
Тема
Re: [SQL] Unique Number KEY
Дата
Msg-id
36D6E70D.ACF4CB7D@digiro.net
Список
Дерево обсуждения
Re: [SQL] Unique Number KEY CIMPOESU Teodor <teo@digiro.net>
Patrice DUMAS wrote:

> Hello,
>
> What is the best way, with PostGres, to create a Unique Number Key
> Generator?
>
> For example, I have a STUDENTS table:
> {
>     StudentNumber    integer;
>     StudentName      char[40];
> ...
> }

you have 2 ways to do it:
1. try something like
      CREATE TABLE  STUDENTS(
           studentID  int4 DEFAULT 'int(now())',
          studentName text );
then if you say:
 INSERT INTO STUDENTS (studentName) VALUES ('Patrice DUMAS jr.') ;
you will get an unique ID generated from a timestamp returned by now() .

2. by using a sequence.See \h create sequence and nextval() function.
      This is a better way to get an ordered ID ( with an increment specified
by you).



В списке pgsql-sql по дате отправления
От: Patrice DUMAS
Дата:
Сообщение: Unique Number KEY
От: Jackson, DeJuan
Дата:
Сообщение: RE: [SQL] Unique Number KEY
FAQ