Subject Re: [firebird-support] Incremental key
Author Bjoern Reimer

TGdO> I'm trying to improve my sistems, and I've seen that incremental key fields
TGdO> is one of my dificults..

TGdO> 1 - I need to show the number when the user click in "insert". ( 344)
TGdO> 2 - The user can change this number
TGdO> 3 - A second user will insert the next record before the first save. (345)
TGdO> 4 - If the first user cancel the record, the next record need to be the same
TGdO> number of the first insert. (344)

Well, sounds somewhat strange.
I think you would like to avoid dupliacte numbers.
But Ok:

First: Don't use this number as primary key of your table.
To access your data rows use a semantic insignificant primary key.

I'd suggest:
* Use a SELECT MAX (Number)+1 FROM TABLE to get the number
* end your transaction
* Use an before insert trigger to check if someone else has selected
this number and do another select max if so and commit your
* use a stored proc to let the user change this number and return an
error or the next free number, if someone else has inserted the
number meanwhile and commit your transaction


SOFTbaer --- reimer@... ---