Received: from localhost (unknown [200.46.204.183]) by postgresql.org (Postfix) with ESMTP id 32DA12E0337 for ; Mon, 11 Feb 2008 06:38:11 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.183]) (amavisd-maia, port 10024) with ESMTP id 79070-01-6 for ; Mon, 11 Feb 2008 06:38:03 -0400 (AST) Received: from smtpout13.attiva.biz (smtpout13.attiva.biz [85.37.16.15]) by postgresql.org (Postfix) with ESMTP id 6B5052E2D6E for ; Mon, 11 Feb 2008 06:25:02 -0400 (AST) Received: from FBCMFE02B12.fbc.local ([192.168.30.89]) by smtpout13.attiva.biz with Microsoft SMTPSVC(6.0.3790.1830); Mon, 11 Feb 2008 11:24:57 +0100 Received: from dream ([88.34.161.130]) by FBCMFE02B12.fbc.local with Microsoft SMTPSVC(6.0.3790.1830); Mon, 11 Feb 2008 11:24:51 +0100 Message-ID: <009b01c86c98$5ba507b0$3102a8c0@dream> Reply-To: "Shavonne Marietta Wijesinghe" From: "Shavonne Marietta Wijesinghe" To: "Shane Ambler" Cc: References: <00a401c86a43$f88de120$3102a8c0@dream> <47AC567F.9020907@Sheeky.Biz> Subject: Re: Serial not nulla Date: Mon, 11 Feb 2008 11:24:59 +0100 Organization: Studio FORM MIME-Version: 1.0 Content-Type: text/plain; format=flowed; charset="iso-8859-1"; reply-type=response Content-Transfer-Encoding: 7bit X-Priority: 3 X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook Express 6.00.2900.3138 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.3198 X-OriginalArrivalTime: 11 Feb 2008 10:24:51.0336 (UTC) FILETIME=[55FA6080:01C86C98] X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200802/73 X-Sequence-Number: 30164 Thanks alot Shane..Just what I wanted.. Didn't think of a solution with 3 primary keys. Have a nice day ^___^ Shavonne Wijesinghe www.studioform.it ----- Original Message ----- From: "Shane Ambler" To: "Shavonne Marietta Wijesinghe" Cc: Sent: Friday, February 08, 2008 2:17 PM Subject: Re: [SQL] Serial not nulla > Shavonne Marietta Wijesinghe wrote: >> Hello >> >> I am working with a database that has a Index number defined as Serial >> NOT NULL >> >> I used this because, >> 1. I want to make sure that when many users login at the same time the >> Index number won't be repeated. >> 2. I don't have to increment it by programming (I use ASP) >> >> But now i have a situation that i need to index numbers. For Example i >> could have a structure like this >> >> INDEX1 - N_SHEET - TOT_SHEET >> 1 - 1 - 1 >> 2 - 1 - 3 >> 2 - 2 - 3 >> 2 - 3 - 3 >> >> N_SHEET and TOT_SHEET are filled by the user (via web) but i need to hold >> on to the INDEX. And while userA is filling the 3 row if userB loggs in i >> need to provide the INDEX1 with 3. >> >> Any idea?? >> > > As well as using the "Serial NOT NULL" you have also defined this column > as PRIMARY KEY (or a unique index) which is what is preventing the > duplicates in that column. (A primary key is enforced with a unique index) > > > From the sample shown you can use all three columns as the primary key > with something similar to - > > ALTER TABLE my_user_sheets DROP CONSTRAINT my_user_sheets_pkey; > ALTER TABLE my_user_sheets ADD PRIMARY KEY ("INDEX1", "N_SHEET", > "TOT_SHEET"); > > (this implies that for each user they will have only one row for each > combination of N_SHEET and TOT_SHEET) If you need to allow them to select > the same 2 sheet numbers more than once then I would suggest you have an > extra column for a primary key and redefine INDEX1 as the user_id. (or > just add a user_id column and leave the INDEX1 as it is) > > > > It's not recommended but you could also have the table without a primary > key allowing duplicate value combinations. This would prevent you updating > a single row though. > > > > -- > > Shane Ambler > pgSQL (at) Sheeky (dot) Biz > > Get Sheeky @ http://Sheeky.Biz