Received: from teo.digiro.net (IDENT:root@teo.digiro.net [194.102.93.15]) by hub.org (8.9.2/8.9.1) with ESMTP id NAA54566 for ; Fri, 26 Feb 1999 13:24:26 -0500 (EST) (envelope-from teo@digiro.net) Received: from digiro.net (root@teo.digiro.net [194.102.93.15]) by teo.digiro.net (8.8.7/8.8.7) with ESMTP id UAA01012; Fri, 26 Feb 1999 20:25:18 +0200 Sender: root@teo.digiro.net Message-ID: <36D6E70D.ACF4CB7D@digiro.net> Date: Fri, 26 Feb 1999 20:25:17 +0200 From: CIMPOESU Teodor Organization: DIGICOM S.A X-Mailer: Mozilla 4.5 [en] (X11; I; Linux 2.0.36 i586) X-Accept-Language: en MIME-Version: 1.0 To: Patrice DUMAS CC: pgsql-sql@postgreSQL.org Subject: Re: [SQL] Unique Number KEY References: <000901be61af$7018d800$ce9efea9@blneige> Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit 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).