Received: from localhost (maia-4.hub.org [200.46.204.183]) by postgresql.org (Postfix) with ESMTP id 56FD19FB648 for ; Wed, 7 Mar 2007 09:16:16 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.183]) (amavisd-new, port 10024) with ESMTP id 67396-08 for ; Wed, 7 Mar 2007 09:16:12 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey-1.7.4 Received: from smtpout18.attiva.biz (smtpout18.attiva.biz [85.37.16.20]) by postgresql.org (Postfix) with ESMTP id 0F0849FB252 for ; Wed, 7 Mar 2007 09:16:10 -0400 (AST) Received: from fbcmfe02b11.fbc.local ([192.168.30.92]) by smtpout18.attiva.biz with Microsoft SMTPSVC(6.0.3790.1830); Wed, 7 Mar 2007 14:16:06 +0100 Received: from dream ([88.34.161.130]) by fbcmfe02b11.fbc.local with Microsoft SMTPSVC(6.0.3790.1830); Wed, 7 Mar 2007 14:16:06 +0100 Message-ID: <007301c760ba$c8acf470$1102a8c0@dream> Reply-To: "Shavonne Marietta Wijesinghe" From: "Shavonne Marietta Wijesinghe" To: References: <003f01c760ac$c8d34980$1102a8c0@dream> <45EEA8C5.9000507@gmail.com> Subject: Re: PRIMARY KEY Date: Wed, 7 Mar 2007 14:16:14 +0100 Organization: Studio FORM MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="----=_NextPart_000_0070_01C760C3.2A086170" X-Priority: 3 X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook Express 6.00.2900.3028 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.3028 X-OriginalArrivalTime: 07 Mar 2007 13:16:06.0430 (UTC) FILETIME=[C38C8BE0:01C760BA] X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=0.253 tagged_above=0 required=5 tests=AWL, BAYES_50, HTML_50_60, HTML_MESSAGE X-Spam-Level: X-Archive-Number: 200703/70 X-Sequence-Number: 27708 This is a multi-part message in MIME format. ------=_NextPart_000_0070_01C760C3.2A086170 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable Thanks alot Mario. It did exactly what i wanted. I shall also take alook = at the link you gave for more details.. Shavonne Wijesinghe ----- Original Message -----=20 From: M.P.Dankoor=20 To: Shavonne Marietta Wijesinghe=20 Cc: pgsql-sql@postgresql.org=20 Sent: Wednesday, March 07, 2007 12:57 PM Subject: Re: [SQL] PRIMARY KEY Hello, Is it possible to redesign your table as follows: create table Mod48_00_2007 ( ID text, N_GEN serial not null, FORMSTORE text, COD_NOTATIO text, PA_COGNOME text, constraint pk_Mod48_00_2007 primary key (N_GEN) ); Your insert simply becomes: INSERT INTO MOD48_00_2007 (ID, FORMSTORE, COD_NOTAIO, PA_COGNOME) = VALUES ('192168217200737122012', '', '00128', 'DE MARTINIS') Do note that you do not refer to the N_GEN column, it will use the = next value, please refer to = http://www.postgresql.org/docs/8.1/interactive/datatype.html#DATATYPE-SER= IAL for more information. Mario Shavonne Marietta Wijesinghe wrote:=20 Hello I have created a table CREATE TABLE MOD48_00_2007 ( ID text, N_GEN int PRIMARY KEY, = FORMSTORE text, COD_NOTAIO text, PA_COGNOME text); And i insert the rows via a form in ASP. When the form loads i have = a functin that goes and gets the value of the field N_GEN adds 1 to it = and shows it to the user. The problem is when i have 2 users working at the same time. For example the last value in my field N_GEN is 2 When both the users A and B loads the form (ASP page) it sees N_GEN = =3D 3 :) So they fill in the form and user A clicks on the button OK and the = record has been inserted with N_GEN =3D 3. But when the user B clicks on = the button the record is not inserted because it has the same key "3" INSERT INTO MOD48_00_2007 (ID, N_GEN, FORMSTORE, COD_NOTAIO, = PA_COGNOME) VALUES ('192168217200737122012', '3', '', '00128', 'DE = MARTINIS') Is there any way i can do this automatically? i mean maybe i have to = use someother property instead of "Primary Key" ?? Thanks Shavonne Wijesinghe ------=_NextPart_000_0070_01C760C3.2A086170 Content-Type: text/html; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable
Thanks alot Mario. It did exactly what = i wanted. I=20 shall also take alook at the link you gave for more = details..
 
 
Shavonne Wijesinghe
 
----- Original Message -----
From:=20 M.P.Dankoor
To: Shavonne Marietta = Wijesinghe=20
Sent: Wednesday, March 07, 2007 = 12:57=20 PM
Subject: Re: [SQL] PRIMARY = KEY

Hello,

Is it possible to redesign your table as=20 follows:

create table Mod48_00_2007 (
ID    =    =20     text,
N_GEN       =  =20 serial     not null,
FORMSTORE =    =20 text,
COD_NOTATIO   text,
PA_COGNOME   =20 text,
constraint pk_Mod48_00_2007 primary key (N_GEN)
);

Your = insert=20 simply becomes:
INSERT INTO MOD48_00_2007 (ID, = FORMSTORE,=20 COD_NOTAIO, PA_COGNOME) VALUES ('192168217200737122012', '', '00128', = 'DE=20 MARTINIS')

Do note that you do not refer to the N_GEN = column,=20 it will use the next value, please refer to http://www.postgresql.org/docs/8.1/interactive/datatype.html= #DATATYPE-SERIAL
for=20 more information.

Mario

Shavonne Marietta Wijesinghe = wrote:=20
Hello
 
I have created = a table
CREATE TABLE MOD48_00_2007 ( ID = text, N_GEN=20 int PRIMARY KEY, FORMSTORE text, COD_NOTAIO text, PA_COGNOME=20 text);
 
And i insert the = rows via a form=20 in ASP. When the form loads i have a functin that goes and gets = the=20 value of the field N_GEN adds 1 to it and shows it to the=20 user.
The problem is when = i have 2 users=20 working at the same time.
 
For example the last value in my field N_GEN = is=20 2
When both the users A and B loads the form = (ASP page)=20 it sees N_GEN =3D 3 :)
 
So they fill in the form and user A clicks = on the=20 button OK and the record has been inserted with N_GEN =3D 3. But = when the user=20 B clicks on the button the record is not inserted because it has the = same=20 key "3"
 
INSERT INTO MOD48_00_2007 (ID, = N_GEN,=20 FORMSTORE, COD_NOTAIO, PA_COGNOME) VALUES ('192168217200737122012', = '3', '',=20 '00128', 'DE MARTINIS')
 
Is there any way i can do this = automatically? i mean=20 maybe i have to use someother property instead of "Primary Key"=20 ??
 
Thanks
 
Shavonne=20 = Wijesinghe

------=_NextPart_000_0070_01C760C3.2A086170--