X-Original-To: pgsql-sql@postgresql.org Received: from spampd.localdomain (postgresql.org [64.49.215.8]) by postgresql.org (Postfix) with ESMTP id 248C2476333 for ; Wed, 23 Apr 2003 14:30:24 -0400 (EDT) Received: from anchor-post-31.mail.demon.net (anchor-post-31.mail.demon.net [194.217.242.89]) by postgresql.org (Postfix) with ESMTP id 7E4DC47632B for ; Wed, 23 Apr 2003 14:30:22 -0400 (EDT) Received: from mwynhau.demon.co.uk ([193.237.186.96] helo=mainbox.archonet.com) by anchor-post-31.mail.demon.net with esmtp (Exim 3.35 #1) id 198P0c-0004JQ-0V; Wed, 23 Apr 2003 19:30:18 +0100 Received: from localhost (localhost.localdomain [127.0.0.1]) by mainbox.archonet.com (Postfix) with ESMTP id 222D11629E; Wed, 23 Apr 2003 19:30:17 +0100 (BST) Received: from client.archonet.com (client.archonet.com [192.168.1.16]) by mainbox.archonet.com (Postfix) with ESMTP id 84D2716240; Wed, 23 Apr 2003 19:30:14 +0100 (BST) Content-Type: text/plain; charset="iso-8859-1" From: Richard Huxton Organization: Archonet Ltd To: Bruce Williams , pgsql-sql@postgresql.org Subject: Re: Invoice Numbers Date: Wed, 23 Apr 2003 19:30:32 +0100 User-Agent: KMail/1.4.3 References: <3EA6B4F3.8D78F9F4@jbs1.com> In-Reply-To: <3EA6B4F3.8D78F9F4@jbs1.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Message-Id: <200304231930.32093.dev@archonet.com> X-Virus-Scanned: by AMaViS snapshot-20020531 X-Spam-Status: No, hits=-38.1 required=5.0 tests=BAYES_10,EMAIL_ATTRIBUTION,IN_REP_TO,QUOTED_EMAIL_TEXT, REFERENCES,REPLY_WITH_QUOTES,USER_AGENT_KMAIL autolearn=ham version=2.50 X-Spam-Level: X-Spam-Checker-Version: SpamAssassin 2.50 (1.173-2003-02-20-exp) X-Archive-Number: 200304/348 X-Sequence-Number: 13049 On Wednesday 23 Apr 2003 4:44 pm, Bruce Williams wrote: > Hi, > > I'm creating an invoice in an Access 2000 report. I would like to know > how can I establish an invoice number that will generate automatically > in a table? Do I have to create my own numbers or do you have a better > suggestion. Thanks If you want sequential invoice numbers with no gaps, then you need to make= =20 sure that only one process allocates numbers at any time. This means you want to either lock the table or use the serializable=20 transaction isolation level while allocating invoice numbers. Allocating the next invoice number is as simple as max(invoice_num)+1 altho= ugh=20 many invoice applications use a "next invoice value" in a system table (whi= ch=20 lets you set up an initial invoice number per company). If you have many clients, you may wish to insert invoices without a number= =20 then create the number in a second transaction to reduce lock contention. T= ry=20 a search on the mailing-list archives for other discussions on this. --=20 Richard Huxton