Re: [SQL] Unique Number KEY
| От | CIMPOESU Teodor |
|---|---|
| Тема | Re: [SQL] Unique Number KEY |
| Дата | |
| Msg-id | 36D6E70D.ACF4CB7D@digiro.net обсуждение исходный текст |
| Ответ на | Unique Number KEY ("Patrice DUMAS" <pdumas@inforoutes-ardeche.fr>) |
| Список | pgsql-sql |
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 по дате отправления: