Subject Re: [firebird-support] Auto Incrementing field
Author Yves Glodt
On Tuesday 09 December 2003 15:41, Bahadir ARMAGAN wrote:
> I have an integer field that an application increments it each time
> it adds a record. But when I run the intances of that application at
> the same time , I get an error because all the instances reading the
> same last value and trying to insert the same incremented value to
> this unique field.
> What is the general methode that is to be followed for this problem?
> Is it possible to create an autoincrement field as in access
> databases? What if I try to make a field (already have unique recodrs
> in it) autoincrement?

ok, assume this table:

create table TEST123 (

and you want ID to be autoincremented.
Follow these steps:

1. Create a generator:
2. Set it's value to the higest ID already used in your DB:
(if you omit this step, ID will start at 1 with the first insert)
3. Use this syntax when you insert a record:

Find a record with ID=1235 and NAME='blablabla' in your DB.

(Of course you could also use a trigger. With a trigger you would not
need to specify the ID column in the insert statement (See message from
Richard Pendered), so your insert would be like this:
INSERT INTO TEST123 (NAME) VALUES ('blablabla');
Youself decide whether this is an advantage for you or not.)

Yves Glodt

> TRANSVARO Elektron Aletleri San. ve Tic. A.S.
> Address: Fatih Cad. Dereboyu Sok. No:12
> 34660 Halkali - Istanbul - Turkey
> Phone: +90 (212) 473 0100
> Fax: +90 (212) 473 0155
> URL:
> E-Mail: mail@...
> NOT: Bu elektronik posta mesaji gizli olup, ayni zamanda ayricalikli
> olabilir; sartlar ne olursa olsun, gondericinin onceden onayini
> almaksizin, baskalarina iletmemeniz, icerigini kopyalamamaniz veya
> baskalarina aciklamamaniz gerekmektedir. Bu mesajin muhatabi
> degilseniz, bu durumu derhal tarafimiza bildirmenizi rica ederiz.
> Internet ├╝zerinden yapilan iletisim guvenli olmayip, verilerin kasten
> veya tesadufen bozulmasi ve virus icermesi olasiligi vardir. Ayrica,
> elektronik posta, resmi olmayan ve cogunlukla kisaltilmis bir
> iletisim yontemidir. Dolayisiyla, burada yer alan bilgi veya
> tavsiyelere, gonderici ile ayrica gorusmeden guvenmeniz normal
> sartlar altinda uygun olmayabilir.
> NOTE: This e-mail is confidential and may also be privileged; under
> no circumstances should you forward it, or copy or disclose its
> contents, to any other person without the prior consent of the
> sender. If you are not an intended recipient of this e-mail, please
> notify us immediately. Internet communications are not secure and
> subject to possible data corruption, either accidentally or on
> purpose, and may contain viruses. Furthermore e-mail is an informal
> and often abbreviated method of communication. For these reasons, it
> will normally be inappropriate to rely on any nformation or advice
> contained herein without also discussing it with the sender.
> [Non-text portions of this message have been removed]
> ------------------------ Yahoo! Groups Sponsor
> ---------------------~--> Buy Ink Cartridges or Refill Kits for your
> HP, Epson, Canon or Lexmark Printer at Free s/h on orders
> $50 or more to the US & Canada.
> ---------------------------------------------------------------------
> To unsubscribe from this group, send an email to:
> Your use of Yahoo! Groups is subject to

Linux 2.4.22-1-k7 #1 Sat Sep 6 02:13:04 EST 2003 i686
20:14:41 up 46 min, 1 user, load average: 0.05, 0.17, 0.27