Re: [SQL] Unique Number KEY

From: CIMPOESU Teodor <teo(at)digiro(dot)net>
To: Patrice DUMAS <pdumas(at)inforoutes-ardeche(dot)fr>
Cc: pgsql-sql(at)postgreSQL(dot)org
Subject: Re: [SQL] Unique Number KEY
Date: 1999-02-26 18:25:17
Message-ID: 36D6E70D.ACF4CB7D@digiro.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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).

In response to

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message Jackson, DeJuan 1999-02-26 18:34:19 RE: [SQL] Unique Number KEY
Previous Message Patrice DUMAS 1999-02-26 17:42:40 Unique Number KEY