Subject Re: [firebird-support] Some explanations Needed
Author Helen Borrie
At 09:58 PM 27/08/2005 -0500, you wrote:
>women_lover_best wrote:
>
> >Hi,
> >when we use generator,why do we use syntax like..
> >if new.id=null
> >new.id=gen(x,1)..why not just use 2nd line?
> >
> >
>This allows the user to supply their own value for ID without having the
>trigger overwrite it. The triggers only supplies a value when the value
>is null.

To add:

It's encouraged to write your autoinc triggers this way, since applications
can fetch the latest generator value into the application and make its
value available before the new row (and its dependents) are posted to the
database. Using the generator this way - knowing the PK value *before* it
is known to the database - makes it possible, for example, for
master-detail structures to be completely atomic.

./heLen