Subject RE: [firebird-support] Re: random number generator?
Author Alan McDonald
> > Curently I am inserting a random number from the application but I
> > want to change this to a trigger or something.
> >
> > I can do what I want using a two-field key, but I would rather not.
> No, you do not need a two-field key. Suppose your client has a few
> salesmen and that the number of salesmen will not exceed 1000 for the
> foreseeable future. Then you initialize your generator to 1 for the
> first computer, 2 for the second and so on and instead of incrementing
> by 1 for each sale you increment the generator by 1000. This
> eliminates the mathematical chance of two identical keys in a very
> simple way.
> Set

Agreed - and the benefit of this method is that you always know which
station screated the record.
Just make sure that wherever you call the generator value (either in your
app code or in triggers) increment the trigger by 1000 or 10000 or even
You can find more info in a paper I wrote here (which has to do with
replication but the same logic applies):
(mind the wrap)